diff --git a/lib/ansible/module_utils/netcfg.py b/lib/ansible/module_utils/netcfg.py index 885205381ec..fd31cb644b4 100644 --- a/lib/ansible/module_utils/netcfg.py +++ b/lib/ansible/module_utils/netcfg.py @@ -66,6 +66,10 @@ class ConfigLine(object): def children(self): return _obj_to_text(self._children) + @property + def child_objs(self): + return self._children + @property def parents(self): return _obj_to_text(self._parents) @@ -368,19 +372,12 @@ class CustomNetworkConfig(NetworkConfig): if S is None: S = list() S.append(configobj) - for child in configobj.children: + for child in configobj.child_objs: if child in S: continue self.expand_section(child, S) return S - def get_object(self, path): - for item in self.items: - if item.text == path[-1]: - parents = [p.text for p in item.parents] - if parents == path[:-1]: - return item - def to_block(self, section): return '\n'.join([item.raw for item in section]) @@ -398,55 +395,3 @@ class CustomNetworkConfig(NetworkConfig): if not obj: raise ValueError('path does not exist in config') return self.expand_section(obj) - - - def add(self, lines, parents=None): - """Adds one or lines of configuration - """ - - ancestors = list() - offset = 0 - obj = None - - ## global config command - if not parents: - for line in to_list(lines): - item = ConfigLine(line) - item.raw = line - if item not in self.items: - self.items.append(item) - - else: - for index, p in enumerate(parents): - try: - i = index + 1 - obj = self.get_section_objects(parents[:i])[0] - ancestors.append(obj) - - except ValueError: - # add parent to config - offset = index * self.indent - obj = ConfigLine(p) - obj.raw = p.rjust(len(p) + offset) - if ancestors: - obj.parents = list(ancestors) - ancestors[-1].children.append(obj) - self.items.append(obj) - ancestors.append(obj) - - # add child objects - for line in to_list(lines): - # check if child already exists - for child in ancestors[-1].children: - if child.text == line: - break - else: - offset = len(parents) * self.indent - item = ConfigLine(line) - item.raw = line.rjust(len(line) + offset) - item.parents = ancestors - ancestors[-1].children.append(item) - self.items.append(item) - - - diff --git a/lib/ansible/modules/network/nxos/nxos_bgp.py b/lib/ansible/modules/network/nxos/nxos_bgp.py index d3ad6c430d9..5e8756c91d8 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp.py @@ -549,7 +549,7 @@ def get_value(arg, config): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) try: asn_regex = '.*router\sbgp\s(?P\d+).*' diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_af.py b/lib/ansible/modules/network/nxos/nxos_bgp_af.py index 48373f36111..2429ced811c 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp_af.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp_af.py @@ -539,7 +539,7 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) try: asn_regex = '.*router\sbgp\s(?P\d+).*' diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py index 3cb2197b57b..a943434e424 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py @@ -372,7 +372,7 @@ def get_custom_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) custom = [ 'log_neighbor_changes', 'pwd', diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py index 907c8ffb521..d8ecccc47b8 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py @@ -503,7 +503,7 @@ def get_custom_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) custom = [ 'allowas_in_max', diff --git a/lib/ansible/modules/network/nxos/nxos_evpn_vni.py b/lib/ansible/modules/network/nxos/nxos_evpn_vni.py index 19cfcb7cf49..e74d594ff47 100644 --- a/lib/ansible/modules/network/nxos/nxos_evpn_vni.py +++ b/lib/ansible/modules/network/nxos/nxos_evpn_vni.py @@ -174,7 +174,7 @@ def get_route_target_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = ['evpn', 'vni {0} l2'.format(module.params['vni'])] config = netcfg.get_section(parents) diff --git a/lib/ansible/modules/network/nxos/nxos_gir.py b/lib/ansible/modules/network/nxos/nxos_gir.py index ed3638ee1d8..04711567ef3 100644 --- a/lib/ansible/modules/network/nxos/nxos_gir.py +++ b/lib/ansible/modules/network/nxos/nxos_gir.py @@ -166,7 +166,6 @@ import re from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show_ascii'): cmds = [command] diff --git a/lib/ansible/modules/network/nxos/nxos_gir_profile_management.py b/lib/ansible/modules/network/nxos/nxos_gir_profile_management.py index 3abcfc2bd3e..3cfd4a0ae2c 100644 --- a/lib/ansible/modules/network/nxos/nxos_gir_profile_management.py +++ b/lib/ansible/modules/network/nxos/nxos_gir_profile_management.py @@ -127,7 +127,7 @@ from ansible.module_utils.netcfg import CustomNetworkConfig def get_existing(module): existing = [] - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) if module.params['mode'] == 'maintenance': parents = ['configure maintenance profile maintenance-mode'] diff --git a/lib/ansible/modules/network/nxos/nxos_hsrp.py b/lib/ansible/modules/network/nxos/nxos_hsrp.py index 40c051ee97b..7d12453757e 100644 --- a/lib/ansible/modules/network/nxos/nxos_hsrp.py +++ b/lib/ansible/modules/network/nxos/nxos_hsrp.py @@ -148,7 +148,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py index a75a5857250..1c448d527ba 100644 --- a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py @@ -238,7 +238,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py b/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py index 58c641347d9..193abcb863b 100644 --- a/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py +++ b/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py @@ -134,7 +134,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_install_os.py b/lib/ansible/modules/network/nxos/nxos_install_os.py index bf10bfd2263..4006cff1b74 100644 --- a/lib/ansible/modules/network/nxos/nxos_install_os.py +++ b/lib/ansible/modules/network/nxos/nxos_install_os.py @@ -122,7 +122,6 @@ import re from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show_ascii'): diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index 3131a583d0f..e270d6c12b2 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -169,7 +169,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig diff --git a/lib/ansible/modules/network/nxos/nxos_interface_ospf.py b/lib/ansible/modules/network/nxos/nxos_interface_ospf.py index b15271c4dff..f20e187eba7 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface_ospf.py +++ b/lib/ansible/modules/network/nxos/nxos_interface_ospf.py @@ -281,7 +281,7 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = ['interface {0}'.format(module.params['interface'].capitalize())] config = netcfg.get_section(parents) if 'ospf' in config: diff --git a/lib/ansible/modules/network/nxos/nxos_ip_interface.py b/lib/ansible/modules/network/nxos/nxos_ip_interface.py index c86c311eab3..0122adb9894 100644 --- a/lib/ansible/modules/network/nxos/nxos_ip_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_ip_interface.py @@ -116,7 +116,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_ntp.py b/lib/ansible/modules/network/nxos/nxos_ntp.py index a934f259f0a..796cb8170ac 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp.py @@ -130,7 +130,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_ntp_auth.py b/lib/ansible/modules/network/nxos/nxos_ntp_auth.py index aed2b1df645..a85b0793e52 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp_auth.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp_auth.py @@ -128,7 +128,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_ntp_options.py b/lib/ansible/modules/network/nxos/nxos_ntp_options.py index 305a93ae877..4d1b668fc40 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp_options.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp_options.py @@ -109,7 +109,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py b/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py index 2745d076db8..051ba156a5e 100644 --- a/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py +++ b/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py @@ -239,7 +239,7 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = ['router ospf {0}'.format(module.params['ospf'])] if module.params['vrf'] != 'default': diff --git a/lib/ansible/modules/network/nxos/nxos_pim_interface.py b/lib/ansible/modules/network/nxos/nxos_pim_interface.py index 06d5225e838..4290f8f5f41 100644 --- a/lib/ansible/modules/network/nxos/nxos_pim_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_pim_interface.py @@ -192,7 +192,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import time diff --git a/lib/ansible/modules/network/nxos/nxos_portchannel.py b/lib/ansible/modules/network/nxos/nxos_portchannel.py index 930753f0e9e..a0637b7c9eb 100644 --- a/lib/ansible/modules/network/nxos/nxos_portchannel.py +++ b/lib/ansible/modules/network/nxos/nxos_portchannel.py @@ -207,7 +207,7 @@ def get_portchannel_mode(interface, protocol, module, netcfg): if protocol != 'LACP': mode = 'on' else: - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = ['interface {0}'.format(interface.capitalize())] body = netcfg.get_section(parents) @@ -281,7 +281,7 @@ def get_portchannel(module, netcfg=None): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) interface_exist = check_interface(module, netcfg) if interface_exist: diff --git a/lib/ansible/modules/network/nxos/nxos_rollback.py b/lib/ansible/modules/network/nxos/nxos_rollback.py index 6b6e4122f88..f3574b70c50 100644 --- a/lib/ansible/modules/network/nxos/nxos_rollback.py +++ b/lib/ansible/modules/network/nxos/nxos_rollback.py @@ -81,7 +81,6 @@ status: from ansible.module_utils.nxos import nxos_argument_spec, run_commands from ansible.module_utils.basic import AnsibleModule - def checkpoint(filename, module): commands = ['terminal dont-ask', 'checkpoint file %s' % filename] run_commands(module, commands) diff --git a/lib/ansible/modules/network/nxos/nxos_smu.py b/lib/ansible/modules/network/nxos/nxos_smu.py index 9cf4d0638e3..b336acbd086 100644 --- a/lib/ansible/modules/network/nxos/nxos_smu.py +++ b/lib/ansible/modules/network/nxos/nxos_smu.py @@ -84,7 +84,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import time import collections diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_community.py b/lib/ansible/modules/network/nxos/nxos_snmp_community.py index c46e537afcf..2923c62de45 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_community.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_community.py @@ -103,7 +103,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_contact.py b/lib/ansible/modules/network/nxos/nxos_snmp_contact.py index 60443c4f593..52568c80bcd 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_contact.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_contact.py @@ -88,7 +88,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_host.py b/lib/ansible/modules/network/nxos/nxos_snmp_host.py index 673735190d3..7f2c4a3c767 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_host.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_host.py @@ -136,7 +136,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_location.py b/lib/ansible/modules/network/nxos/nxos_snmp_location.py index db25f721d40..0801dd5c3d0 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_location.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_location.py @@ -95,7 +95,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_traps.py b/lib/ansible/modules/network/nxos/nxos_snmp_traps.py index 5d3332e9e05..2d4213ffed9 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_traps.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_traps.py @@ -106,7 +106,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_user.py b/lib/ansible/modules/network/nxos/nxos_snmp_user.py index c38ef6f997a..06011eb364c 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_user.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_user.py @@ -117,7 +117,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_static_route.py b/lib/ansible/modules/network/nxos/nxos_static_route.py index f4a711d6030..3c474371f6b 100644 --- a/lib/ansible/modules/network/nxos/nxos_static_route.py +++ b/lib/ansible/modules/network/nxos/nxos_static_route.py @@ -136,7 +136,7 @@ def state_present(module, candidate, prefix): def state_absent(module, candidate, prefix): - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) commands = list() parents = 'vrf context {0}'.format(module.params['vrf']) invoke('set_route', module, commands, prefix) @@ -161,7 +161,7 @@ def fix_prefix_to_regex(prefix): def get_existing(module, prefix, warnings): key_map = ['tag', 'pref', 'route_name', 'next_hop'] - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = 'vrf context {0}'.format(module.params['vrf']) prefix_to_regex = fix_prefix_to_regex(prefix) diff --git a/lib/ansible/modules/network/nxos/nxos_switchport.py b/lib/ansible/modules/network/nxos/nxos_switchport.py index 7ab1e3efbe6..3fc38373942 100644 --- a/lib/ansible/modules/network/nxos/nxos_switchport.py +++ b/lib/ansible/modules/network/nxos/nxos_switchport.py @@ -159,7 +159,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_udld.py b/lib/ansible/modules/network/nxos/nxos_udld.py index e1bc20c86c4..2a4fc8e611b 100644 --- a/lib/ansible/modules/network/nxos/nxos_udld.py +++ b/lib/ansible/modules/network/nxos/nxos_udld.py @@ -113,7 +113,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_udld_interface.py b/lib/ansible/modules/network/nxos/nxos_udld_interface.py index ed9409726b5..25a24689b1c 100644 --- a/lib/ansible/modules/network/nxos/nxos_udld_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_udld_interface.py @@ -112,7 +112,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_vpc.py b/lib/ansible/modules/network/nxos/nxos_vpc.py index 93c1c306a9f..b35237984d0 100644 --- a/lib/ansible/modules/network/nxos/nxos_vpc.py +++ b/lib/ansible/modules/network/nxos/nxos_vpc.py @@ -150,7 +150,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show'): if module.params['transport'] == 'cli': diff --git a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py index a5a139a08c9..da9fcb0f542 100644 --- a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py @@ -102,7 +102,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show'): if module.params['transport'] == 'cli': diff --git a/lib/ansible/modules/network/nxos/nxos_vrf.py b/lib/ansible/modules/network/nxos/nxos_vrf.py index 27515295339..bc78c5c6ce7 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf.py @@ -124,7 +124,6 @@ import re from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show'): transport = module.params['provider']['transport'] diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_af.py b/lib/ansible/modules/network/nxos/nxos_vrf_af.py index 2a9d7788b37..8179377eef6 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_af.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_af.py @@ -144,7 +144,7 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = ['vrf context {0}'.format(module.params['vrf'])] parents.append('address-family {0} {1}'.format(module.params['afi'], diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index 56b407e55b9..0ef121cd8a2 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -104,7 +104,6 @@ import re from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig WARNINGS = [] diff --git a/lib/ansible/modules/network/nxos/nxos_vrrp.py b/lib/ansible/modules/network/nxos/nxos_vrrp.py index d3cde3fa830..dd472f50f9e 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrrp.py +++ b/lib/ansible/modules/network/nxos/nxos_vrrp.py @@ -142,7 +142,6 @@ import re from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig def execute_show_command(command, module, command_type='cli_show'): if module.params['transport'] == 'cli': diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_domain.py b/lib/ansible/modules/network/nxos/nxos_vtp_domain.py index 915650562d6..2893b8b2c19 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_domain.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_domain.py @@ -89,7 +89,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_password.py b/lib/ansible/modules/network/nxos/nxos_vtp_password.py index 191d8e0865b..1d93e532369 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_password.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_password.py @@ -106,7 +106,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_version.py b/lib/ansible/modules/network/nxos/nxos_vtp_version.py index 9ca4bf025c2..9307c2a04e4 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_version.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_version.py @@ -84,7 +84,6 @@ changed: from ansible.module_utils.nxos import get_config, load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import CustomNetworkConfig import re diff --git a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py index e18e0d11113..d2030b064d7 100644 --- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py +++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py @@ -202,7 +202,7 @@ def get_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) interface_string = 'interface {0}'.format(module.params['interface'].lower()) parents = [interface_string] diff --git a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py index da411d88fca..5482bd83659 100644 --- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py +++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py @@ -217,7 +217,7 @@ def get_custom_value(arg, config, module): def get_existing(module, args): existing = {} - netcfg = get_config(module) + netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) custom = [ 'assoc_vrf', @@ -283,6 +283,10 @@ def state_present(module, existing, proposed, candidate): for peer in value: commands.append('{0} {1}'.format(key, peer)) + elif key == 'mcast-group' and value != existing_commands.get(key): + commands.append('no {0}'.format(key)) + commands.append('{0} {1}'.format(key, value)) + elif value is True: commands.append(key) @@ -422,13 +426,17 @@ def main(): else: candidate = CustomNetworkConfig(indent=3) invoke('state_%s' % state, module, existing, proposed, candidate) - - try: - response = load_config(module, candidate) - result.update(response) - except ShellError: - exc = get_exception() - module.fail_json(msg=str(exc)) + result['changed'] = False + for k, v in proposed.items(): + if k in existing: + if existing[k] != proposed[k] or state == 'absent': + result['changed'] = True + if k not in existing and state == 'present': + result['changed'] = True + if module.check_mode: + module.exit_json(commands=candidate) + else: + load_config(module, candidate) else: result['updates'] = []