diff --git a/lib/ansible/modules/network/nxos/nxos_vpc.py b/lib/ansible/modules/network/nxos/nxos_vpc.py index b35237984d..8bbb7b5936 100644 --- a/lib/ansible/modules/network/nxos/nxos_vpc.py +++ b/lib/ansible/modules/network/nxos/nxos_vpc.py @@ -147,10 +147,11 @@ changed: sample: true ''' -from ansible.module_utils.nxos import get_config, load_config, run_commands +from ansible.module_utils.nxos import load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule + def execute_show_command(command, module, command_type='cli_show'): if module.params['transport'] == 'cli': if "section" not in command: @@ -158,7 +159,10 @@ def execute_show_command(command, module, command_type='cli_show'): cmds = [command] body = run_commands(module, cmds) elif module.params['transport'] == 'nxapi': - cmds = [command] + if command_type == 'cli_show_ascii': + cmds = [command] + else: + cmds = [command + ' | json'] body = run_commands(module, cmds) return body @@ -177,10 +181,9 @@ def get_vrf_list(module): command = 'show vrf all' vrf_table = None - body = execute_show_command(command, module) - try: - vrf_table = body[0]['TABLE_vrf']['ROW_vrf'] + body = execute_show_command(command, module)[0] + vrf_table = body['TABLE_vrf']['ROW_vrf'] except (KeyError, AttributeError): return [] @@ -219,7 +222,7 @@ def get_vpc(module): if domain != 'not configured': delay_restore = None pkl_src = None - role_priority = None + role_priority = '32667' system_priority = None pkl_dest = None pkl_vrf = None @@ -249,7 +252,6 @@ def get_vpc(module): if 'peer-gateway' in each: peer_gw = True - command = 'show vpc peer-keepalive' body = execute_show_command(command, module)[0] @@ -299,7 +301,7 @@ def get_commands_to_config_vpc(module, vpc, domain, existing): pkl_dest = existing.get('pkl_dest') if pkl_src and pkl_dest: pkl_command = ('peer-keepalive destination {0}' - ' source {1} vrf {2}'.format(pkl_dest, pkl_src, pkl_vrf)) + ' source {1} vrf {2}'.format(pkl_dest, pkl_src, pkl_vrf)) commands.append(pkl_command) if vpc.get('auto_recovery') is False: @@ -307,10 +309,16 @@ def get_commands_to_config_vpc(module, vpc, domain, existing): else: vpc['auto_recovery'] = '' - if vpc.get('peer_gw') is False: - vpc['peer_gw'] = 'no' + if 'peer_gw' in vpc: + if vpc.get('peer_gw') is False: + vpc['peer_gw'] = 'no' + else: + vpc['peer_gw'] = '' else: - vpc['peer_gw'] = '' + if existing.get('peer_gw') is False: + vpc['peer_gw'] = 'no' + else: + vpc['peer_gw'] = '' CONFIG_ARGS = { 'role_priority': 'role priority {role_priority}', @@ -318,7 +326,7 @@ def get_commands_to_config_vpc(module, vpc, domain, existing): 'delay_restore': 'delay restore {delay_restore}', 'peer_gw': '{peer_gw} peer-gateway', 'auto_recovery': '{auto_recovery} auto-recovery', - } + } for param, value in vpc.items(): command = CONFIG_ARGS.get(param, 'DNE').format(**vpc) @@ -359,7 +367,7 @@ def main(): argument_spec.update(nxos_argument_spec) module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True) + supports_check_mode=True) warnings = list() check_args(module, warnings) @@ -442,4 +450,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 971b632360..6f1c616f7d 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -401,7 +401,6 @@ lib/ansible/modules/network/nxos/nxos_system.py lib/ansible/modules/network/nxos/nxos_udld.py lib/ansible/modules/network/nxos/nxos_udld_interface.py lib/ansible/modules/network/nxos/nxos_user.py -lib/ansible/modules/network/nxos/nxos_vpc.py lib/ansible/modules/network/nxos/nxos_vpc_interface.py lib/ansible/modules/network/nxos/nxos_vrf.py lib/ansible/modules/network/nxos/nxos_vrf_interface.py