diff --git a/lib/ansible/module_utils/network/iosxr/iosxr.py b/lib/ansible/module_utils/network/iosxr/iosxr.py index 126dc1928d1..7f914380f81 100644 --- a/lib/ansible/module_utils/network/iosxr/iosxr.py +++ b/lib/ansible/module_utils/network/iosxr/iosxr.py @@ -48,7 +48,6 @@ try: except ImportError: HAS_XML = False -_DEVICE_CONFIGS = {} _EDIT_OPS = frozenset(['merge', 'create', 'replace', 'delete']) BASE_1_0 = "{urn:ietf:params:xml:ns:netconf:base:1.0}" @@ -78,7 +77,7 @@ iosxr_provider_spec = { 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), 'timeout': dict(type='int'), - 'transport': dict(), + 'transport': dict(type='str', default='cli', choices=['cli', 'netconf']), } iosxr_argument_spec = { @@ -356,8 +355,6 @@ def commit_config(module, comment=None, confirmed=False, confirm_timeout=None, p def get_oper(module, filter=None): - global _DEVICE_CONFIGS - conn = get_connection(module) if filter is not None: @@ -367,25 +364,16 @@ def get_oper(module, filter=None): def get_config(module, config_filter=None, source='running'): - global _DEVICE_CONFIGS - conn = get_connection(module) - if config_filter is not None: - key = (source + ' ' + ' '.join(config_filter)).strip().rstrip() - else: - key = source - config = _DEVICE_CONFIGS.get(key) - if config: - return config - else: - out = conn.get_config(source=source, filter=config_filter) - if is_netconf(module): - out = to_xml(conn.get_config(source=source, filter=config_filter)) + # Note: Does not cache config in favour of latest config on every get operation. + out = conn.get_config(source=source, filter=config_filter) + if is_netconf(module): + out = to_xml(conn.get_config(source=source, filter=config_filter)) + + cfg = out.strip() - cfg = out.strip() - _DEVICE_CONFIGS.update({key: cfg}) - return cfg + return cfg def load_config(module, command_filter, commit=False, replace=False, diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py index 8c37bad99a1..c9efaeae1f5 100644 --- a/lib/ansible/plugins/action/iosxr.py +++ b/lib/ansible/plugins/action/iosxr.py @@ -45,15 +45,14 @@ class ActionModule(_ActionModule): provider = load_provider(iosxr_provider_spec, self._task.args) pc = copy.deepcopy(self._play_context) if self._task.action in ['iosxr_netconf', 'iosxr_config', 'iosxr_command'] or \ - (provider['transport'] == 'cli' and (self._task.action == 'iosxr_banner' or - self._task.action == 'iosxr_facts' or self._task.action == 'iosxr_logging' or - self._task.action == 'iosxr_system' or self._task.action == 'iosxr_user' or - self._task.action == 'iosxr_interface')): + (provider['transport'] == 'cli'): pc.connection = 'network_cli' pc.port = int(provider['port'] or self._play_context.port or 22) - else: + elif provider['transport'] == 'netconf': pc.connection = 'netconf' pc.port = int(provider['port'] or self._play_context.port or 830) + else: + return {'failed': True, 'msg': 'Transport type %s is not valid for this module' % provider['transport']} pc.network_os = 'iosxr' pc.remote_addr = provider['host'] or self._play_context.remote_addr diff --git a/lib/ansible/plugins/action/net_base.py b/lib/ansible/plugins/action/net_base.py index 7ed726e1ad1..1aaa1024e57 100644 --- a/lib/ansible/plugins/action/net_base.py +++ b/lib/ansible/plugins/action/net_base.py @@ -37,6 +37,9 @@ except ImportError: from ansible.utils.display import Display display = Display() +_CLI_ONLY_MODULES = frozenset(['junos_netconf', 'iosxr_netconf', 'iosxr_config', 'iosxr_command']) +_NETCONF_SUPPORTED_PLATFORMS = frozenset(['junos', 'iosxr']) + class ActionModule(ActionBase): @@ -57,7 +60,8 @@ class ActionModule(ActionBase): module = load_module(module_name, f, p, d) self.provider = load_provider(module.get_provider_argspec(), self._task.args) - if play_context.network_os == 'junos': + if self.provider.get('transport') == 'netconf' and play_context.network_os in _NETCONF_SUPPORTED_PLATFORMS \ + and self._task.action not in _CLI_ONLY_MODULES: play_context.connection = 'netconf' play_context.port = int(self.provider['port'] or self._play_context.port or 830) elif self.provider.get('transport') in ('nxapi', 'eapi') and play_context.network_os in ('nxos', 'eos'): diff --git a/test/integration/targets/iosxr_interface/tasks/netconf.yaml b/test/integration/targets/iosxr_interface/tasks/netconf.yaml index 0e92b1c60fb..2b284b5886e 100644 --- a/test/integration/targets/iosxr_interface/tasks/netconf.yaml +++ b/test/integration/targets/iosxr_interface/tasks/netconf.yaml @@ -17,6 +17,6 @@ - name: run test case (connection=local) include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run