ansible.netcommon
ansible.netcommon copied to clipboard
telnet newline for commands/exit does not work with telnet running on DOS
SUMMARY
The newline for DOS is \r\n not \n. When connecting to an ArcaOS 5.0.7 system commands just hang.
ISSUE TYPE
- Bug Report
COMPONENT NAME
- telnet
ANSIBLE VERSION
ansible [core 2.12.7]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/jason/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.10/site-packages/ansible
ansible collection location = /home/jason/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.5 (main, Jun 9 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)]
jinja version = 3.0.3
libyaml = True
COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 2.2.0
CONFIGURATION
ANSIBLE_COW_SELECTION(env: ANSIBLE_COW_SELECTION) = random
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
LOCALHOST_WARNING(env: ANSIBLE_LOCALHOST_WARNING) = False
OS / ENVIRONMENT
Running on Fedora 36. Ansible, netcommon, etc. all installed via RPMs and up to date. Connecting to an ArcaOS 5.0.7 system via telnet plugin.
STEPS TO REPRODUCE
Run telnetd on an ArcaOS system. Try to connect using the telnet module.
EXPECTED RESULTS
Telnet works
ACTUAL RESULTS
Commands hang, looking at the prompt on the system (it's possible to run the connection in the Foreground command lines hang iwth a ^J character at the end.
I patched the plugin like so and it then works correctly if I set dos_newlines: yes on the task.
b6cc151..d7c483e 100644
--- a/plugins/action/telnet.py
+++ b/plugins/action/telnet.py
@@ -54,6 +54,7 @@ class ActionModule(ActionBase):
pause = int(self._task.args.get("pause", 1))
send_newline = self._task.args.get("send_newline", False)
+ dos_newlines = self._task.args.get("dos_newlines", False)
login_prompt = to_text(
self._task.args.get("login_prompt", "login: ")
@@ -75,8 +76,13 @@ class ActionModule(ActionBase):
output = []
try:
+ if dos_newlines:
+ newline = '\r\n'
+ else:
+ newline = '\n'
+
if send_newline:
- tn.write(b"\n")
+ tn.write(to_bytes(newline))
tn.read_until(to_bytes(login_prompt))
tn.write(to_bytes(user + "\n"))
@@ -89,7 +95,7 @@ class ActionModule(ActionBase):
for cmd in commands:
display.vvvvv(">>> %s" % cmd)
- tn.write(to_bytes(cmd + "\n"))
+ tn.write(to_bytes(cmd + newline))
index, match, out = tn.expect(
list(map(to_bytes, prompts)), timeout=timeout
)
@@ -97,7 +103,7 @@ class ActionModule(ActionBase):
output.append(out)
sleep(pause)
- tn.write(b"exit\n")
+ tn.write(to_bytes("exit" + newline))
except EOFError as e:
result["failed"] = True