Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal_initial_newline to network_cli module #593

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/terminal_initial_newline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- network_cli - add `terminal_initial_newline` parameter as an option for terminal plugins.
20 changes: 20 additions & 0 deletions docs/ansible.netcommon.network_cli_connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,26 @@ Parameters
<div>The answer to reply with if the <code>terminal_initial_prompt</code> is matched. The value can be a single answer or a list of answers for multiple terminal_initial_prompt. In case the login menu has multiple prompts the sequence of the prompt and excepted answer should be in same order and the value of <em>terminal_prompt_checkall</em> should be set to <em>True</em> if all the values in <code>terminal_initial_prompt</code> are expected to be matched and set to <em>False</em> if any one login prompt is to be matched.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>terminal_initial_newline</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>
<b>Default:</b><br/><div style="color: blue">"no"</div>
</td>
<td>
<div>var: ansible_terminal_initial_newline</div>
</td>
<td>
<div>This boolean flag, that when set to <em>True</em> will send newline on initial connection establishment to the remote device.</div>
<div>This can be useful for equipment which does not send an initial header until it receives some input, like Serial-to-SSH multiplexer hardware.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
18 changes: 18 additions & 0 deletions plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@
response, for example I('re.I').
vars:
- name: ansible_terminal_stderr_re
terminal_initial_newline:
type: boolean
description:
- This boolean flag, that when set to I(True) will send newline on initial
connection establishment to the remote device.
- This can be useful for equipment which does not send an initial header until
it receives some input, like Serial-to-SSH multiplexer hardware.
default: false
vars:
- name: ansible_terminal_initial_newline
terminal_initial_prompt:
type: list
elements: string
Expand Down Expand Up @@ -658,6 +668,11 @@ def _connect(self):
"loaded terminal plugin for network_os %s" % self._network_os,
)

terminal_initial_newline = (
self.get_option("terminal_initial_newline")
or self._terminal.terminal_initial_newline
)

terminal_initial_prompt = (
self.get_option("terminal_initial_prompt") or self._terminal.terminal_initial_prompt
)
Expand All @@ -670,6 +685,9 @@ def _connect(self):
)
check_all = self.get_option("terminal_initial_prompt_checkall") or False

if terminal_initial_newline:
self.send(command=b"", sendonly=True, newline=True)

self.receive(
prompts=terminal_initial_prompt,
answer=terminal_initial_answer,
Expand Down
3 changes: 3 additions & 0 deletions plugins/plugin_utils/terminal_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class TerminalBase(TerminalBaseBase):
re.compile(rb"\x1b\[m"), # ANSI reset code
]

#: Send newline after initial session connection
terminal_initial_newline = False

#: terminal initial prompt
terminal_initial_prompt = None

Expand Down
Loading