From 85cc5ea129117dff9daae2a8cd20a65baeb578d2 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Thu, 15 Mar 2018 12:49:35 -0400 Subject: [PATCH] Raise error when trying to use older iosxr modules with netconf (#37423) --- lib/ansible/plugins/action/iosxr.py | 7 +++++-- lib/ansible/plugins/netconf/iosxr.py | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py index 40a39b68df..9c978a21f0 100644 --- a/lib/ansible/plugins/action/iosxr.py +++ b/lib/ansible/plugins/action/iosxr.py @@ -42,12 +42,12 @@ class ActionModule(_ActionModule): del tmp # tmp no longer has any effect socket_path = None + force_cli = self._task.action in ('iosxr_netconf', 'iosxr_config', 'iosxr_command', 'iosxr_facts') if self._play_context.connection == 'local': 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'): + if force_cli or provider['transport'] == 'cli': pc.connection = 'network_cli' pc.port = int(provider['port'] or self._play_context.port or 22) elif provider['transport'] == 'netconf': @@ -75,6 +75,9 @@ class ActionModule(_ActionModule): task_vars['ansible_socket'] = socket_path elif self._play_context.connection in ('netconf', 'network_cli'): + if force_cli and self._play_context.connection != 'network_cli': + return {'failed': True, 'msg': 'Connection type %s is not valid for module %s' % + (self._play_context.connection, self._task.action)} provider = self._task.args.get('provider', {}) if any(provider.values()): display.warning('provider is unnecessary when using {0} and will be ignored'.format(self._play_context.connection)) diff --git a/lib/ansible/plugins/netconf/iosxr.py b/lib/ansible/plugins/netconf/iosxr.py index 13216bba2a..ed189e30c4 100644 --- a/lib/ansible/plugins/netconf/iosxr.py +++ b/lib/ansible/plugins/netconf/iosxr.py @@ -73,7 +73,6 @@ def transform_reply(): if sys.version < '3': return reply else: - print("utf8") return reply.encode('UTF-8')