From 4fe719f8ec40e4740dbc4fe783095958c1c4bbcf Mon Sep 17 00:00:00 2001 From: Dominic <2497502+Domoninic@users.noreply.github.com> Date: Sun, 9 Jul 2023 19:13:41 +0200 Subject: [PATCH 1/5] add send_carriage_return to telnet.py action plugin add sending of "\r" if send_carriage_return flag is true, allows connection to IOSv devices console under GNS3 --- plugins/action/telnet.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/action/telnet.py b/plugins/action/telnet.py index a6f5b5189..6b5aed77b 100644 --- a/plugins/action/telnet.py +++ b/plugins/action/telnet.py @@ -46,6 +46,7 @@ def run(self, tmp=None, task_vars=None): pause = int(self._task.args.get("pause", 1)) send_newline = self._task.args.get("send_newline", False) + send_carriage_return = self._task.args.get("send_carriage_return", False) login_prompt = to_text(self._task.args.get("login_prompt", "login: ")) password_prompt = to_text(self._task.args.get("password_prompt", "Password: ")) @@ -62,6 +63,8 @@ def run(self, tmp=None, task_vars=None): try: if send_newline: self.tn.write(b"\n") + if send_carriage_return: + self.tn.write(b"\r") self.await_prompts([login_prompt], timeout) self.tn.write(to_bytes(user + "\n")) From 6ab60a379ba73192f1f60fc27f078248e3054f25 Mon Sep 17 00:00:00 2001 From: Dominic <2497502+Domoninic@users.noreply.github.com> Date: Sun, 9 Jul 2023 19:15:51 +0200 Subject: [PATCH 2/5] add send_carriage_return documentation to telnet.py module --- plugins/modules/telnet.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/modules/telnet.py b/plugins/modules/telnet.py index f3169a065..53b19e5e0 100644 --- a/plugins/modules/telnet.py +++ b/plugins/modules/telnet.py @@ -83,6 +83,12 @@ required: false type: bool default: false + send_carriage_return: + description: + - Sends a carriage return character upon successful connection to start the terminal session. + required: false + type: bool + default: false notes: - The C(environment) keyword does not work with this task author: From f5d79507c187e716b0f61e0679178be80e3b1396 Mon Sep 17 00:00:00 2001 From: Dominic <2497502+Domoninic@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:31:58 +0200 Subject: [PATCH 3/5] Update telnet.py - move send_carriage_return to happen before send_newline It makes more sense to send to do send_carriage_return before send_newline. Not only is this the expected order "\r\n" but in case of cisco iosV on GNS3 the send_carriage_return needs be the first thing send to get any response. --- plugins/modules/telnet.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/telnet.py b/plugins/modules/telnet.py index 075d0b15a..7b4fc49c7 100644 --- a/plugins/modules/telnet.py +++ b/plugins/modules/telnet.py @@ -78,18 +78,19 @@ required: false type: int default: 1 - send_newline: + send_carriage_return: description: - - Sends a newline character upon successful connection to start the terminal session. + - Sends a carriage return character upon successful connection to start the terminal session, this occurs before send_newline option. required: false type: bool default: false - send_carriage_return: + send_newline: description: - - Sends a carriage return character upon successful connection to start the terminal session. + - Sends a newline character upon successful connection to start the terminal session. required: false type: bool default: false + notes: - The C(environment) keyword does not work with this task author: From a7d0ed531f6a6e77cddad6b1e85aa11ddc709198 Mon Sep 17 00:00:00 2001 From: Dominic <2497502+Domoninic@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:32:31 +0200 Subject: [PATCH 4/5] Update telnet.py - move send_carriage_return to happen before send_newline It makes more sense to send to do send_carriage_return before send_newline. Not only is this the expected order "\r\n" but in case of cisco iosV on GNS3 the send_carriage_return needs be the first thing send to get any response. --- plugins/action/telnet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/action/telnet.py b/plugins/action/telnet.py index 59289d3b4..241bd55c0 100644 --- a/plugins/action/telnet.py +++ b/plugins/action/telnet.py @@ -48,8 +48,8 @@ def run(self, tmp=None, task_vars=None): timeout = int(self._task.args.get("timeout", 120)) pause = int(self._task.args.get("pause", 1)) + send_carriage_return = self._task.args.get("send_carriage_return", False) send_newline = self._task.args.get("send_newline", False) - send_carriage_return = self._task.args.get("send_carriage_return", False) login_prompt = to_text(self._task.args.get("login_prompt", "login: ")) password_prompt = to_text(self._task.args.get("password_prompt", "Password: ")) @@ -64,10 +64,10 @@ def run(self, tmp=None, task_vars=None): self.output = bytes() try: + if send_carriage_return: + self.tn.write(b"\r") if send_newline: self.tn.write(b"\n") - if send_carriage_return: - self.tn.write(b"\r") self.await_prompts([login_prompt], timeout) self.tn.write(to_bytes(user + "\n")) From 79400c888789028cd0098d9263e38c3ad8c70789 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:57:59 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/ansible.netcommon.telnet_module.rst | 19 +++++++++++++++++++ plugins/action/telnet.py | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/ansible.netcommon.telnet_module.rst b/docs/ansible.netcommon.telnet_module.rst index 78a0020e2..dc697bfb7 100644 --- a/docs/ansible.netcommon.telnet_module.rst +++ b/docs/ansible.netcommon.telnet_module.rst @@ -164,6 +164,25 @@ Parameters <div>List of prompts expected before sending next command</div> </td> </tr> + <tr> + <td colspan="1"> + <div class="ansibleOptionAnchor" id="parameter-"></div> + <b>send_carriage_return</b> + <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> + <div style="font-size: small"> + <span style="color: purple">boolean</span> + </div> + </td> + <td> + <ul style="margin: 0; padding: 0"><b>Choices:</b> + <li><div style="color: blue"><b>no</b> ←</div></li> + <li>yes</li> + </ul> + </td> + <td> + <div>Sends a carriage return character upon successful connection to start the terminal session, this occurs before send_newline option.</div> + </td> + </tr> <tr> <td colspan="1"> <div class="ansibleOptionAnchor" id="parameter-"></div> diff --git a/plugins/action/telnet.py b/plugins/action/telnet.py index 241bd55c0..34d1fda14 100644 --- a/plugins/action/telnet.py +++ b/plugins/action/telnet.py @@ -48,7 +48,7 @@ def run(self, tmp=None, task_vars=None): timeout = int(self._task.args.get("timeout", 120)) pause = int(self._task.args.get("pause", 1)) - send_carriage_return = self._task.args.get("send_carriage_return", False) + send_carriage_return = self._task.args.get("send_carriage_return", False) send_newline = self._task.args.get("send_newline", False) login_prompt = to_text(self._task.args.get("login_prompt", "login: ")) @@ -65,7 +65,7 @@ def run(self, tmp=None, task_vars=None): self.output = bytes() try: if send_carriage_return: - self.tn.write(b"\r") + self.tn.write(b"\r") if send_newline: self.tn.write(b"\n")