From 28055bbf8fb80e265a7068d4d8ed119595895f04 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Wed, 18 Sep 2019 19:40:10 +0530 Subject: [PATCH] Fix traceback error in IOS and IOSXR when ran with empty config (#62423) * fix changelog * Fix traceback error in IOS and IOSXR when ran without config (#62400) * fixes issue 61321 * complete iosxr * fix ios_vlans Signed-off-by: Sumit Jaiswal (cherry picked from commit 7a5a5e7c87daee1d343a432894ff04a2251d6349) --- .../62400-ios-iosxr-traceback-with-empty-config.yaml | 3 +++ lib/ansible/modules/network/ios/ios_interfaces.py | 5 +++++ lib/ansible/modules/network/ios/ios_l2_interfaces.py | 5 +++++ lib/ansible/modules/network/ios/ios_l3_interfaces.py | 5 +++++ lib/ansible/modules/network/ios/ios_lacp.py | 4 ++++ lib/ansible/modules/network/ios/ios_lacp_interfaces.py | 5 +++++ lib/ansible/modules/network/ios/ios_lag_interfaces.py | 6 ++++++ lib/ansible/modules/network/ios/ios_lldp_global.py | 4 ++++ lib/ansible/modules/network/ios/ios_lldp_interfaces.py | 5 +++++ lib/ansible/modules/network/ios/ios_vlans.py | 5 +++++ lib/ansible/modules/network/iosxr/iosxr_interfaces.py | 5 +++++ lib/ansible/modules/network/iosxr/iosxr_l2_interfaces.py | 5 +++++ lib/ansible/modules/network/iosxr/iosxr_l3_interfaces.py | 5 +++++ 13 files changed, 62 insertions(+) create mode 100644 changelogs/fragments/62400-ios-iosxr-traceback-with-empty-config.yaml diff --git a/changelogs/fragments/62400-ios-iosxr-traceback-with-empty-config.yaml b/changelogs/fragments/62400-ios-iosxr-traceback-with-empty-config.yaml new file mode 100644 index 00000000000..5f2115c387d --- /dev/null +++ b/changelogs/fragments/62400-ios-iosxr-traceback-with-empty-config.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "Fix traceback error in IOS and IOSXR when ran with empty config (https://github.com/ansible/ansible/pull/62400)" diff --git a/lib/ansible/modules/network/ios/ios_interfaces.py b/lib/ansible/modules/network/ios/ios_interfaces.py index 28c500677bc..4988f029be3 100644 --- a/lib/ansible/modules/network/ios/ios_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_interfaces.py @@ -389,7 +389,12 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_l2_interfaces.py b/lib/ansible/modules/network/ios/ios_l2_interfaces.py index 388b3a4273f..4b8d13793c1 100644 --- a/lib/ansible/modules/network/ios/ios_l2_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_l2_interfaces.py @@ -348,7 +348,12 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=L2_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = L2_Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_l3_interfaces.py b/lib/ansible/modules/network/ios/ios_l3_interfaces.py index a440d91bd1d..22b0e222bfa 100644 --- a/lib/ansible/modules/network/ios/ios_l3_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_l3_interfaces.py @@ -426,7 +426,12 @@ def main(): Main entry point for module execution :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=L3_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = L3_Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_lacp.py b/lib/ansible/modules/network/ios/ios_lacp.py index 7ff26a04636..1ebe3b3cef6 100644 --- a/lib/ansible/modules/network/ios/ios_lacp.py +++ b/lib/ansible/modules/network/ios/ios_lacp.py @@ -170,7 +170,11 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',))] + module = AnsibleModule(argument_spec=LacpArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Lacp(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_lacp_interfaces.py b/lib/ansible/modules/network/ios/ios_lacp_interfaces.py index 7ebb497b3f5..d9e52e39cfb 100644 --- a/lib/ansible/modules/network/ios/ios_lacp_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_lacp_interfaces.py @@ -347,7 +347,12 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=Lacp_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Lacp_Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_lag_interfaces.py b/lib/ansible/modules/network/ios/ios_lag_interfaces.py index 12c153f04b8..b5351c6dd8e 100644 --- a/lib/ansible/modules/network/ios/ios_lag_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_lag_interfaces.py @@ -374,8 +374,14 @@ def main(): Main entry point for module execution :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=Lag_interfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) + result = Lag_interfaces(module).execute_module() module.exit_json(**result) diff --git a/lib/ansible/modules/network/ios/ios_lldp_global.py b/lib/ansible/modules/network/ios/ios_lldp_global.py index 5165b2221c1..49c146f8d29 100644 --- a/lib/ansible/modules/network/ios/ios_lldp_global.py +++ b/lib/ansible/modules/network/ios/ios_lldp_global.py @@ -241,7 +241,11 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',))] + module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Lldp_global(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_lldp_interfaces.py b/lib/ansible/modules/network/ios/ios_lldp_interfaces.py index 2079f5b5da0..c1bbc274e43 100644 --- a/lib/ansible/modules/network/ios/ios_lldp_interfaces.py +++ b/lib/ansible/modules/network/ios/ios_lldp_interfaces.py @@ -485,7 +485,12 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=Lldp_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Lldp_Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/ios/ios_vlans.py b/lib/ansible/modules/network/ios/ios_vlans.py index 2d76dc18b37..7de87dbb527 100644 --- a/lib/ansible/modules/network/ios/ios_vlans.py +++ b/lib/ansible/modules/network/ios/ios_vlans.py @@ -448,7 +448,12 @@ def main(): :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=VlansArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Vlans(module).execute_module() diff --git a/lib/ansible/modules/network/iosxr/iosxr_interfaces.py b/lib/ansible/modules/network/iosxr/iosxr_interfaces.py index 02a239c821e..1012ec2729f 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_interfaces.py +++ b/lib/ansible/modules/network/iosxr/iosxr_interfaces.py @@ -349,7 +349,12 @@ def main(): Main entry point for module execution :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/iosxr/iosxr_l2_interfaces.py b/lib/ansible/modules/network/iosxr/iosxr_l2_interfaces.py index 16aee85d9a4..9b8b8c118f3 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_l2_interfaces.py +++ b/lib/ansible/modules/network/iosxr/iosxr_l2_interfaces.py @@ -413,7 +413,12 @@ def main(): Main entry point for module execution :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=L2_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = L2_Interfaces(module).execute_module() diff --git a/lib/ansible/modules/network/iosxr/iosxr_l3_interfaces.py b/lib/ansible/modules/network/iosxr/iosxr_l3_interfaces.py index 7814a04f0fe..3901adfb680 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_l3_interfaces.py +++ b/lib/ansible/modules/network/iosxr/iosxr_l3_interfaces.py @@ -408,7 +408,12 @@ def main(): Main entry point for module execution :returns: the result form module invocation """ + required_if = [('state', 'merged', ('config',)), + ('state', 'replaced', ('config',)), + ('state', 'overridden', ('config',))] + module = AnsibleModule(argument_spec=L3_InterfacesArgs.argument_spec, + required_if=required_if, supports_check_mode=True) result = L3_Interfaces(module).execute_module()