restore the ability to issue commands over junos cli (#28025)
* restore the ability to issue commands over junos cli * add warn message for invalid arguments * fix issue when checking if provider transport is set
This commit is contained in:
parent
5fbbf0e75a
commit
edc3507c98
2 changed files with 16 additions and 1 deletions
|
@ -174,6 +174,7 @@ from ansible.module_utils.junos import junos_argument_spec, check_args, get_conf
|
|||
from ansible.module_utils.netcli import Conditional, FailedConditionalError
|
||||
from ansible.module_utils.netconf import send_request
|
||||
from ansible.module_utils.six import string_types, iteritems
|
||||
from ansible.module_utils.connection import Connection
|
||||
|
||||
try:
|
||||
from lxml.etree import Element, SubElement, tostring
|
||||
|
@ -364,6 +365,18 @@ def main():
|
|||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
if module.params['provider'] and module.params['provider']['transport'] == 'cli':
|
||||
if any((module.params['wait_for'], module.params['match'], module.params['rpcs'])):
|
||||
module.warn('arguments wait_for, match, rpcs are not supported when using transport=cli')
|
||||
commands = module.params['commands']
|
||||
conn = Connection(module)
|
||||
output = list()
|
||||
for cmd in commands:
|
||||
output.append(conn.get(cmd))
|
||||
lines = [out.split('\n') for out in output]
|
||||
result = {'changed': False, 'stdout': output, 'stdout_lines': lines}
|
||||
module.exit_json(**result)
|
||||
|
||||
items = list()
|
||||
items.extend(parse_commands(module, warnings))
|
||||
items.extend(parse_rpcs(module))
|
||||
|
|
|
@ -28,6 +28,7 @@ from ansible.module_utils.junos import junos_argument_spec
|
|||
from ansible.module_utils.six import iteritems
|
||||
from ansible.plugins import connection_loader, module_loader
|
||||
from ansible.plugins.action.normal import ActionModule as _ActionModule
|
||||
from ansible.module_utils.connection import Connection
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
|
@ -59,9 +60,10 @@ class ActionModule(_ActionModule):
|
|||
|
||||
pc.remote_addr = provider['host'] or self._play_context.remote_addr
|
||||
|
||||
if self._task.action == 'junos_netconf':
|
||||
if self._task.action == 'junos_netconf' or (provider['transport'] == 'cli' and self._task.action == 'junos_command'):
|
||||
pc.connection = 'network_cli'
|
||||
pc.port = int(provider['port'] or self._play_context.port or 22)
|
||||
|
||||
else:
|
||||
pc.connection = 'netconf'
|
||||
pc.port = int(provider['port'] or self._play_context.port or 830)
|
||||
|
|
Loading…
Reference in a new issue