Beispiel #1
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'bigip_imish_config' else False
        persistent_connection = self._play_context.connection.split('.')[-1]
        socket_path = None
        transport = 'rest'

        if persistent_connection == 'network_cli':
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                display.warning("'provider' is unnecessary when using 'network_cli' and will be ignored")
        elif self._play_context.connection == 'local':
            provider = load_provider(f5_provider_spec, self._task.args)
            transport = provider['transport'] or transport

            display.vvvv('connection transport is %s' % transport, self._play_context.remote_addr)

            if transport == 'cli':
                pc = copy.deepcopy(self._play_context)
                pc.connection = 'network_cli'
                pc.network_os = 'bigip'
                pc.remote_addr = provider.get('server', self._play_context.remote_addr)
                pc.port = int(provider['server_port'] or self._play_context.port or 22)
                pc.remote_user = provider.get('user', self._play_context.connection_user)
                pc.password = provider.get('password', self._play_context.password)
                pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
                command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)

                display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
                connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)
                connection.set_options(direct={'persistent_command_timeout': command_timeout})

                socket_path = connection.run()
                display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
                if not socket_path:
                    return {
                        'failed': True,
                        'msg': 'Unable to open shell. Please see: '
                               'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'
                    }

                task_vars['ansible_socket'] = socket_path

        if (self._play_context.connection == 'local' and transport == 'cli') or persistent_connection == 'network_cli':
            # make sure we are in the right cli context which should be
            # enable mode and not config module
            if socket_path is None:
                socket_path = self._connection.socket_path
            conn = Connection(socket_path)
            out = conn.get_prompt()
            while '(config' in to_text(out, errors='surrogate_then_replace').strip():
                display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
                conn.send_command('exit')
                out = conn.get_prompt()

        result = super(ActionModule, self).run(task_vars=task_vars)
        return result
Beispiel #2
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'dellos6_config' else False
        socket_path = None
        persistent_connection = self._play_context.connection.split('.')[-1]

        if persistent_connection == 'network_cli':
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                display.warning(
                    'provider is unnecessary when using network_cli and will be ignored'
                )
                del self._task.args['provider']
        elif self._play_context.connection == 'local':
            provider = load_provider(dellos6_provider_spec, self._task.args)
            pc = copy.deepcopy(self._play_context)
            pc.connection = 'network_cli'
            pc.network_os = 'dellos6'
            pc.remote_addr = provider['host'] or self._play_context.remote_addr
            pc.port = int(provider['port'] or self._play_context.port or 22)
            pc.remote_user = provider[
                'username'] or self._play_context.connection_user
            pc.password = provider['password'] or self._play_context.password
            pc.private_key_file = provider[
                'ssh_keyfile'] or self._play_context.private_key_file
            command_timeout = int(provider['timeout']
                                  or C.PERSISTENT_COMMAND_TIMEOUT)
            pc.become = provider['authorize'] or False
            if pc.become:
                pc.become_method = 'enable'
            pc.become_pass = provider['auth_pass']

            display.vvv('using connection plugin %s' % pc.connection,
                        pc.remote_addr)
            connection = self._shared_loader_obj.connection_loader.get(
                'persistent', pc, sys.stdin, task_uuid=self._task._uuid)
            connection.set_options(
                direct={'persistent_command_timeout': command_timeout})

            socket_path = connection.run()
            display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
            if not socket_path:
                return {
                    'failed':
                    True,
                    'msg':
                    'unable to open shell. Please see: ' +
                    'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'
                }

            task_vars['ansible_socket'] = socket_path

        result = super(ActionModule, self).run(task_vars=task_vars)
        return result
Beispiel #3
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'aruba_config' else False

        if self._play_context.connection != 'local':
            return dict(
                failed=True,
                msg='invalid connection specified, expected connection=local, '
                    'got %s' % self._play_context.connection
            )

        provider = load_provider(aruba_provider_spec, self._task.args)

        pc = copy.deepcopy(self._play_context)
        pc.connection = 'network_cli'
        pc.network_os = 'aruba'
        pc.remote_addr = provider['host'] or self._play_context.remote_addr
        pc.port = int(provider['port'] or self._play_context.port or 22)
        pc.remote_user = provider['username'] or self._play_context.connection_user
        pc.password = provider['password'] or self._play_context.password
        pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
        command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)

        display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)
        connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)
        connection.set_options(direct={'persistent_command_timeout': command_timeout})

        socket_path = connection.run()
        display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
        if not socket_path:
            return {'failed': True,
                    'msg': 'unable to open shell. Please see: ' +
                           'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'}

        task_vars['ansible_socket'] = socket_path

        if self._play_context.become_method == 'enable':
            self._play_context.become = False
            self._play_context.become_method = None

        result = super(ActionModule, self).run(task_vars=task_vars)
        return result
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'iosxr_config' else False
        force_cli = module_name in ('iosxr_netconf', 'iosxr_config', 'iosxr_command', 'iosxr_facts')
        persistent_connection = self._play_context.connection.split('.')[-1]
        warnings = []

        if self._play_context.connection == 'local':
            provider = load_provider(iosxr_provider_spec, self._task.args)
            pc = copy.deepcopy(self._play_context)
            pc.network_os = 'cisco.iosxr.iosxr'
            if force_cli or provider['transport'] == 'cli':
                pc.connection = 'ansible.netcommon.network_cli'
                pc.port = int(provider['port'] or self._play_context.port or 22)
            elif provider['transport'] == 'netconf':
                pc.connection = 'ansible.netcommon.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.remote_addr = provider['host'] or self._play_context.remote_addr
            pc.port = int(provider['port'] or self._play_context.port or 22)
            pc.remote_user = provider['username'] or self._play_context.connection_user
            pc.password = provider['password'] or self._play_context.password

            connection = self._shared_loader_obj.connection_loader.get('ansible.netcommon.persistent', pc, sys.stdin,
                                                                       task_uuid=self._task._uuid)

            # TODO: Remove below code after ansible minimal is cut out
            if connection is None:
                pc.network_os = 'iosxr'
                if pc.connection.split('.')[-1] == 'netconf':
                    pc.connection = 'netconf'
                else:
                    pc.connection = 'network_cli'

                connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)

            display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)

            command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
            connection.set_options(direct={'persistent_command_timeout': command_timeout})

            socket_path = connection.run()
            display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
            if not socket_path:
                return {'failed': True,
                        'msg': 'unable to open shell. Please see: ' +
                               'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'}

            task_vars['ansible_socket'] = socket_path
            warnings.append(['connection local support for this module is deprecated and will be removed in version 2.14, use connection %s' % pc.connection])
        elif persistent_connection in ('netconf', 'network_cli'):
            if force_cli and persistent_connection != 'network_cli':
                return {'failed': True, 'msg': 'Connection type %s is not valid for module %s' %
                        (self._play_context.connection, module_name)}
            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))
                del self._task.args['provider']
        else:
            return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection}

        result = super(ActionModule, self).run(task_vars=task_vars)
        if warnings:
            if 'warnings' in result:
                result['warnings'].extend(warnings)
            else:
                result['warnings'] = warnings
        return result
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'ce_config' else False
        socket_path = None
        persistent_connection = self._play_context.connection.split('.')[-1]

        if self._play_context.connection == 'local':
            provider = load_provider(ce_provider_spec, self._task.args)
            transport = provider['transport'] or 'cli'

            display.vvvv('connection transport is %s' % transport,
                         self._play_context.remote_addr)

            if transport == 'cli':
                pc = copy.deepcopy(self._play_context)
                pc.connection = 'network_cli'
                pc.network_os = 'ce'
                pc.remote_addr = provider[
                    'host'] or self._play_context.remote_addr
                pc.port = int(provider['port'] or self._play_context.port
                              or 22)
                pc.remote_user = provider[
                    'username'] or self._play_context.connection_user
                pc.password = provider[
                    'password'] or self._play_context.password
                command_timeout = int(provider['timeout']
                                      or C.PERSISTENT_COMMAND_TIMEOUT)
                self._task.args['provider'] = provider.update(
                    host=pc.remote_addr,
                    port=pc.port,
                    username=pc.remote_user,
                    password=pc.password)
                if module_name in [
                        'ce_netconf'
                ] or module_name not in CLI_SUPPORTED_MODULES:
                    pc.connection = 'netconf'
                display.vvv(
                    'using connection plugin %s (was local)' % pc.connection,
                    pc.remote_addr)
                connection = self._shared_loader_obj.connection_loader.get(
                    'persistent', pc, sys.stdin, task_uuid=self._task._uuid)
                connection.set_options(
                    direct={'persistent_command_timeout': command_timeout})

                socket_path = connection.run()
                display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
                if not socket_path:
                    return {
                        'failed':
                        True,
                        'msg':
                        'unable to open shell. Please see: ' +
                        'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'
                    }

                task_vars['ansible_socket'] = socket_path
                # make sure a transport value is set in args
                self._task.args['transport'] = transport
                self._task.args['provider'] = provider
        elif persistent_connection in ('netconf', 'network_cli'):
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                display.warning(
                    'provider is unnecessary when using %s and will be ignored'
                    % self._play_context.connection)
                del self._task.args['provider']

            if (persistent_connection == 'network_cli' and module_name not in CLI_SUPPORTED_MODULES) or \
                    (persistent_connection == 'netconf' and module_name in CLI_SUPPORTED_MODULES):
                return {
                    'failed':
                    True,
                    'msg':
                    "Connection type '%s' is not valid for '%s' module." %
                    (self._play_context.connection, self._task.action)
                }

        result = super(ActionModule, self).run(task_vars=task_vars)
        return result
Beispiel #6
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'eos_config' else False
        persistent_connection = self._play_context.connection.split('.')[-1]
        warnings = []

        if persistent_connection in ('network_cli', 'httpapi'):
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)
                del self._task.args['provider']
            if self._task.args.get('transport'):
                display.warning('transport is unnecessary when using %s and will be ignored' % self._play_context.connection)
                del self._task.args['transport']
        elif self._play_context.connection == 'local':
            provider = load_provider(eos_provider_spec, self._task.args)
            transport = provider['transport'] or 'cli'

            display.vvvv('connection transport is %s' % transport, self._play_context.remote_addr)

            if transport == 'cli':
                pc = copy.deepcopy(self._play_context)
                pc.connection = 'ansible.netcommon.network_cli'
                pc.network_os = 'arista.eos.eos'
                pc.remote_addr = provider['host'] or self._play_context.remote_addr
                pc.port = int(provider['port'] or self._play_context.port or 22)
                pc.remote_user = provider['username'] or self._play_context.connection_user
                pc.password = provider['password'] or self._play_context.password
                pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
                pc.become = provider['authorize'] or False
                if pc.become:
                    pc.become_method = 'enable'
                pc.become_pass = provider['auth_pass']

                connection = self._shared_loader_obj.connection_loader.get('ansible.netcommon.persistent', pc, sys.stdin,
                                                                           task_uuid=self._task._uuid)

                # TODO: Remove below code after ansible minimal is cut out
                if connection is None:
                    pc.connection = 'network_cli'
                    pc.network_os = 'eos'
                    connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)

                display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)

                command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
                connection.set_options(direct={'persistent_command_timeout': command_timeout})

                socket_path = connection.run()
                display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
                if not socket_path:
                    return {'failed': True,
                            'msg': 'unable to open shell. Please see: ' +
                                   'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'}

                task_vars['ansible_socket'] = socket_path
                warnings.append(['connection local support for this module is deprecated and will be removed in version 2.14,'
                                 ' use connection %s' % pc.connection])
            else:
                self._task.args['provider'] = ActionModule.eapi_implementation(provider, self._play_context)
                warnings.append(['connection local support for this module is deprecated and will be removed in version 2.14,'
                                 ' use connection either httpapi or ansible.netcommon.httpapi (whichever is applicable)'])
        else:
            return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection}

        result = super(ActionModule, self).run(task_vars=task_vars)
        if warnings:
            if 'warnings' in result:
                result['warnings'].extend(warnings)
            else:
                result['warnings'] = warnings
        return result
Beispiel #7
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'nxos_config' else False
        persistent_connection = self._play_context.connection.split('.')[-1]
        warnings = []

        if (self._play_context.connection in ('httpapi', 'local') or self._task.args.get('provider', {}).get('transport') == 'nxapi') \
                and module_name in ('nxos_file_copy', 'nxos_nxapi'):
            return {
                'failed':
                True,
                'msg':
                "Transport type 'nxapi' is not valid for '%s' module." %
                (module_name)
            }

        if module_name == 'nxos_file_copy':
            self._task.args['host'] = self._play_context.remote_addr
            self._task.args['password'] = self._play_context.password
            if self._play_context.connection == 'network_cli':
                self._task.args['username'] = self._play_context.remote_user
            elif self._play_context.connection == 'local':
                self._task.args[
                    'username'] = self._play_context.connection_user

        if module_name == 'nxos_install_os':
            connection = self._connection
            if connection.transport == 'local':
                persistent_command_timeout = C.PERSISTENT_COMMAND_TIMEOUT
                persistent_connect_timeout = C.PERSISTENT_CONNECT_TIMEOUT
            else:
                persistent_command_timeout = connection.get_option(
                    'persistent_command_timeout')
                persistent_connect_timeout = connection.get_option(
                    'persistent_connect_timeout')

            display.vvvv(
                'PERSISTENT_COMMAND_TIMEOUT is %s' %
                str(persistent_command_timeout),
                self._play_context.remote_addr)
            display.vvvv(
                'PERSISTENT_CONNECT_TIMEOUT is %s' %
                str(persistent_connect_timeout),
                self._play_context.remote_addr)
            if persistent_command_timeout < 600 or persistent_connect_timeout < 600:
                msg = 'PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT'
                msg += ' must be set to 600 seconds or higher when using nxos_install_os module.'
                msg += ' Current persistent_command_timeout setting:' + str(
                    persistent_command_timeout)
                msg += ' Current persistent_connect_timeout setting:' + str(
                    persistent_connect_timeout)
                return {'failed': True, 'msg': msg}

        if persistent_connection in ('network_cli', 'httpapi'):
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                display.warning(
                    'provider is unnecessary when using %s and will be ignored'
                    % self._play_context.connection)
                del self._task.args['provider']
            if self._task.args.get('transport'):
                display.warning(
                    'transport is unnecessary when using %s and will be ignored'
                    % self._play_context.connection)
                del self._task.args['transport']

            if module_name == 'nxos_gir':
                conn = Connection(self._connection.socket_path)
                persistent_command_timeout = conn.get_option(
                    'persistent_command_timeout')
                gir_timeout = 200
                if persistent_command_timeout < gir_timeout:
                    conn.set_option('persistent_command_timeout', gir_timeout)
                    msg = "timeout value extended to %ss for nxos_gir" % gir_timeout
                    display.warning(msg)

        elif self._play_context.connection == 'local':
            provider = load_provider(nxos_provider_spec, self._task.args)
            transport = provider['transport'] or 'cli'

            display.vvvv('connection transport is %s' % transport,
                         self._play_context.remote_addr)

            if transport == 'cli':
                pc = copy.deepcopy(self._play_context)
                pc.connection = 'ansible.netcommon.network_cli'
                pc.network_os = 'cisco.nxos.nxos'
                pc.remote_addr = provider[
                    'host'] or self._play_context.remote_addr
                pc.port = int(provider['port'] or self._play_context.port
                              or 22)
                pc.remote_user = provider[
                    'username'] or self._play_context.connection_user
                pc.password = provider[
                    'password'] or self._play_context.password
                pc.private_key_file = provider[
                    'ssh_keyfile'] or self._play_context.private_key_file
                pc.become = provider['authorize'] or False
                if pc.become:
                    pc.become_method = 'enable'
                pc.become_pass = provider['auth_pass']

                connection = self._shared_loader_obj.connection_loader.get(
                    'ansible.netcommon.persistent',
                    pc,
                    sys.stdin,
                    task_uuid=self._task._uuid)

                # TODO: Remove below code after ansible minimal is cut out
                if connection is None:
                    pc.connection = 'network_cli'
                    pc.network_os = 'nxos'
                    connection = self._shared_loader_obj.connection_loader.get(
                        'persistent',
                        pc,
                        sys.stdin,
                        task_uuid=self._task._uuid)

                display.vvv(
                    'using connection plugin %s (was local)' % pc.connection,
                    pc.remote_addr)

                command_timeout = int(
                    provider['timeout']
                ) if provider['timeout'] else connection.get_option(
                    'persistent_command_timeout')
                connection.set_options(
                    direct={'persistent_command_timeout': command_timeout})

                socket_path = connection.run()
                display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
                if not socket_path:
                    return {
                        'failed':
                        True,
                        'msg':
                        'unable to open shell. Please see: ' +
                        'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'
                    }

                task_vars['ansible_socket'] = socket_path

            else:
                self._task.args[
                    'provider'] = ActionModule.nxapi_implementation(
                        provider, self._play_context)
                warnings.append([
                    'connection local support for this module is deprecated and will be removed in version 2.14,'
                    ' use connection either httpapi or ansible.netcommon.httpapi (whichever is applicable)'
                ])
        else:
            return {
                'failed':
                True,
                'msg':
                'Connection type %s is not valid for this module' %
                self._play_context.connection
            }

        result = super(ActionModule, self).run(task_vars=task_vars)
        if warnings:
            if 'warnings' in result:
                result['warnings'].extend(warnings)
            else:
                result['warnings'] = warnings
        return result
Beispiel #8
0
    def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        module_name = self._task.action.split('.')[-1]
        self._config_module = True if module_name == 'junos_config' else False
        persistent_connection = self._play_context.connection.split('.')[-1]
        warnings = []

        if self._play_context.connection == 'local':
            provider = load_provider(junos_provider_spec, self._task.args)
            pc = copy.deepcopy(self._play_context)
            pc.network_os = 'junipernetworks.junos.junos'
            pc.remote_addr = provider['host'] or self._play_context.remote_addr

            if provider['transport'] == 'cli' and module_name 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'], module_name)}

            if module_name == 'junos_netconf' or (provider['transport'] == 'cli' and module_name == 'junos_command'):
                pc.connection = 'ansible.netcommon.network_cli'
                pc.port = int(provider['port'] or self._play_context.port or 22)
            else:
                pc.connection = 'ansible.netcommon.netconf'
                pc.port = int(provider['port'] or self._play_context.port or 830)

            pc.remote_user = provider['username'] or self._play_context.connection_user
            pc.password = provider['password'] or self._play_context.password
            pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file

            connection = self._shared_loader_obj.connection_loader.get('ansible.netcommon.persistent', pc, sys.stdin,
                                                                       task_uuid=self._task._uuid)

            # TODO: Remove below code after ansible minimal is cut out
            if connection is None:
                pc.network_os = 'junos'
                if pc.connection.split('.')[-1] == 'netconf':
                    pc.connection = 'netconf'
                else:
                    pc.connection = 'network_cli'

                connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)

            display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr)

            command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout')
            connection.set_options(direct={'persistent_command_timeout': command_timeout})

            socket_path = connection.run()
            display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)
            if not socket_path:
                return {'failed': True,
                        'msg': 'unable to open shell. Please see: ' +
                               'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'}

            task_vars['ansible_socket'] = socket_path
            warnings.append(['connection local support for this module is deprecated and will be removed in version 2.14, use connection %s' % pc.connection])
        elif persistent_connection in ('netconf', 'network_cli'):
            provider = self._task.args.get('provider', {})
            if any(provider.values()):
                # for legacy reasons provider value is required for junos_facts(optional) and junos_package
                # modules as it uses junos_eznc library to connect to remote host
                if not (module_name == 'junos_facts' or module_name == 'junos_package' or module_name == 'junos_scp'):
                    display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)
                    del self._task.args['provider']

            if (persistent_connection == 'network_cli' and module_name not in CLI_SUPPORTED_MODULES) or \
                    (persistent_connection == 'netconf' and module_name in CLI_SUPPORTED_MODULES[0:2]):
                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, module_name)}

        result = super(ActionModule, self).run(task_vars=task_vars)
        if warnings:
            if 'warnings' in result:
                result['warnings'].extend(warnings)
            else:
                result['warnings'] = warnings
        return result