update telnet module (#28100)
* accepts list of prompts to expect * updates doc strings
This commit is contained in:
parent
40d29936a4
commit
5ee7862793
2 changed files with 31 additions and 10 deletions
|
@ -43,10 +43,11 @@ options:
|
||||||
description:
|
description:
|
||||||
- timeout for remote operations
|
- timeout for remote operations
|
||||||
default: 120
|
default: 120
|
||||||
command:
|
prompts:
|
||||||
description:
|
description:
|
||||||
- Command to execute in telnet session
|
- List of prompts expected before sending next command
|
||||||
required: True
|
required: False
|
||||||
|
default: ['$']
|
||||||
pause:
|
pause:
|
||||||
description:
|
description:
|
||||||
- Seconds to pause between each command issued
|
- Seconds to pause between each command issued
|
||||||
|
@ -59,11 +60,27 @@ author:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Force ssh on IOS
|
- name: send configuration commands to IOS
|
||||||
telnet:
|
telnet:
|
||||||
command: transport input ssh
|
|
||||||
user: cisco
|
user: cisco
|
||||||
password: cisco
|
password: cisco
|
||||||
|
login_prompt: "Username: "
|
||||||
|
prompts:
|
||||||
|
- "[>|#]"
|
||||||
|
commands:
|
||||||
|
- terminal length 0
|
||||||
|
- configure terminal
|
||||||
|
- hostname ios01
|
||||||
|
|
||||||
|
- name: run show commands
|
||||||
|
telnet:
|
||||||
|
user: cisco
|
||||||
|
password: cisco
|
||||||
|
login_prompt: "Username: "
|
||||||
|
prompts:
|
||||||
|
- "[>|#]"
|
||||||
|
commands:
|
||||||
|
- terminal length 0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
|
|
@ -42,6 +42,7 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
login_prompt = self._task.args.get('login_prompt', "login: ")
|
login_prompt = self._task.args.get('login_prompt', "login: ")
|
||||||
password_prompt = self._task.args.get('password_prompt', "Password: ")
|
password_prompt = self._task.args.get('password_prompt', "Password: ")
|
||||||
|
prompts = self._task.args.get('prompts', "$ ")
|
||||||
commands = self._task.args.get('command')
|
commands = self._task.args.get('command')
|
||||||
|
|
||||||
if isinstance(commands, text_type):
|
if isinstance(commands, text_type):
|
||||||
|
@ -54,15 +55,18 @@ class ActionModule(ActionBase):
|
||||||
output = []
|
output = []
|
||||||
try:
|
try:
|
||||||
tn.read_until(login_prompt)
|
tn.read_until(login_prompt)
|
||||||
tn.write('%s\n' % user)
|
tn.write('%s\n' % to_native(user))
|
||||||
|
|
||||||
if password:
|
if password:
|
||||||
tn.read_until(password_prompt)
|
tn.read_until(password_prompt)
|
||||||
tn.write('%s\n' % password)
|
tn.write('%s\n' % to_native(password))
|
||||||
|
|
||||||
|
tn.expect(prompts)
|
||||||
|
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
tn.write(cmd)
|
tn.write('%s\n' % to_native(cmd))
|
||||||
output.append(tn.read_until(''))
|
index, match, out = tn.expect(prompts)
|
||||||
|
output.append(out)
|
||||||
sleep(pause)
|
sleep(pause)
|
||||||
|
|
||||||
tn.write("exit\n")
|
tn.write("exit\n")
|
||||||
|
@ -76,6 +80,6 @@ class ActionModule(ActionBase):
|
||||||
result['output'] = output
|
result['output'] = output
|
||||||
else:
|
else:
|
||||||
result['failed'] = True
|
result['failed'] = True
|
||||||
result['msg'] = 'Telnet requries a command to execute'
|
result['msg'] = 'Telnet requires a command to execute'
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue