From 67d6f2c0d614ca1fa1b74d98a1428fe525e1fcee Mon Sep 17 00:00:00 2001 From: Gabriele Date: Fri, 30 Sep 2016 16:24:44 -0400 Subject: [PATCH] Fixing nxos_vlan (#5005) * Fixing nxos_vlan * Fixing docstring * Fixing docstring --- lib/ansible/modules/network/nxos/nxos_vlan.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vlan.py b/lib/ansible/modules/network/nxos/nxos_vlan.py index e328e89bf45..bb39b1c10bf 100644 --- a/lib/ansible/modules/network/nxos/nxos_vlan.py +++ b/lib/ansible/modules/network/nxos/nxos_vlan.py @@ -982,6 +982,15 @@ def execute_config_command(commands, module): clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) + except AttributeError: + try: + commands.insert(0, 'configure') + module.cli.add_commands(commands, output='config') + module.cli.run_commands() + except ShellError: + clie = get_exception() + module.fail_json(msg='Error sending CLI commands', + error=str(clie), commands=commands) def get_cli_body_ssh(command, response, module): @@ -1014,6 +1023,19 @@ def execute_show(cmds, module, command_type=None): clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) + except AttributeError: + try: + if command_type: + command_type = command_type_map.get(command_type) + module.cli.add_commands(cmds, output=command_type) + response = module.cli.run_commands() + else: + module.cli.add_commands(cmds, raw=True) + response = module.cli.run_commands() + except ShellError: + clie = get_exception() + module.fail_json(msg='Error sending {0}'.format(cmds), + error=str(clie)) return response @@ -1069,7 +1091,6 @@ def main(): proposed_vlans_list = numerical_sort(vlan_range_to_list( vlan_id or vlan_range)) existing_vlans_list = numerical_sort(get_list_of_vlans(module)) - commands = [] existing = None @@ -1104,7 +1125,7 @@ def main(): end_state_vlans_list = existing_vlans_list if commands: - if existing: + if existing.get('mapped_vni'): if (existing.get('mapped_vni') != proposed.get('mapped_vni') and existing.get('mapped_vni') != '0' and proposed.get('mapped_vni') != 'default'): commands.insert(1, 'no vn-segment') @@ -1115,6 +1136,8 @@ def main(): execute_config_command(commands, module) changed = True end_state_vlans_list = numerical_sort(get_list_of_vlans(module)) + if 'configure' in commands: + commands.pop(0) if vlan_id: end_state = get_vlan(vlan_id, module)