From 94fe139f0459518b5e74ed3ed7c09ac9c9b462f2 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 24 Jun 2019 15:18:17 +0530 Subject: [PATCH] Revert "Fix junos module transport check (#58050)" (#58270) This reverts commit f864f621d87bea7eeb6d9c5908524ff811486d2a. --- lib/ansible/plugins/action/junos.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/ansible/plugins/action/junos.py b/lib/ansible/plugins/action/junos.py index 1d9917e907..c49e4f56ea 100644 --- a/lib/ansible/plugins/action/junos.py +++ b/lib/ansible/plugins/action/junos.py @@ -22,20 +22,18 @@ __metaclass__ = type import sys import copy +from ansible import constants as C from ansible.module_utils._text import to_text from ansible.module_utils.connection import Connection from ansible.module_utils.network.common.utils import load_provider from ansible.module_utils.network.junos.junos import junos_provider_spec -from ansible.plugins.loader import module_loader +from ansible.plugins.loader import connection_loader, module_loader from ansible.plugins.action.network import ActionModule as ActionNetworkModule from ansible.utils.display import Display display = Display() -NETCONF_SUPPORTED_MODULES = frozenset(('junos_banner', 'junos_command', 'junos_config', 'junos_facts', 'junos_interface', - 'junos_l2_interface', 'junos_l3_interface', 'junos_linkagg', 'junos_lldp', - 'junos_lldp_interface', 'junos_logging', 'junos_package', 'junos_rpc', 'junos_scp', - 'junos_static_route', 'junos_system', 'junos_user', 'junos_vlan', 'junos_vrf')) +CLI_SUPPORTED_MODULES = ['junos_netconf', 'junos_command'] class ActionModule(ActionNetworkModule): @@ -51,22 +49,15 @@ class ActionModule(ActionNetworkModule): socket_path = None if self._play_context.connection == 'local': - args_provider = self._task.args.get('provider', {}) provider = load_provider(junos_provider_spec, self._task.args) pc = copy.deepcopy(self._play_context) pc.network_os = 'junos' pc.remote_addr = provider['host'] or self._play_context.remote_addr - if self._task.action in ['junos_netconf', 'junos_ping']: - if args_provider.get('transport') == 'netconf': - return {'failed': True, 'msg': "Transport type 'netconf' is not valid for '%s' module. " - "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" - % self._task.action} - else: - if provider['transport'] == 'netconf' and self._task.action not in NETCONF_SUPPORTED_MODULES: - return {'failed': True, 'msg': "Transport type '%s' is not valid for '%s' module. " - "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" - % (provider['transport'], self._task.action)} + if provider['transport'] == 'cli' and self._task.action not in CLI_SUPPORTED_MODULES: + return {'failed': True, 'msg': "Transport type '%s' is not valid for '%s' module. " + "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" + % (provider['transport'], self._task.action)} if self._task.action == 'junos_netconf' or (provider['transport'] == 'cli' and self._task.action == 'junos_command'): pc.connection = 'network_cli' @@ -102,7 +93,8 @@ class ActionModule(ActionNetworkModule): display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection) del self._task.args['provider'] - if self._play_context.connection == 'netconf' and self._task.action not in NETCONF_SUPPORTED_MODULES: + if (self._play_context.connection == 'network_cli' and self._task.action not in CLI_SUPPORTED_MODULES) or \ + (self._play_context.connection == 'netconf' and self._task.action == 'junos_netconf'): return {'failed': True, 'msg': "Connection type '%s' is not valid for '%s' module. " "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" % (self._play_context.connection, self._task.action)}