Skip to content

Commit e7dd539

Browse files
committed
Add terminal_initial_newline to network_cli module
`terminal_initial_newline`, when set to true sends a single newline character to the remote device immediately after initially connecting. This allows network_cli to work with some types of equipment which fail to send any data when SSH connectivity is initially established, such as serial-port multiplexers.
1 parent fada835 commit e7dd539

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

plugins/connection/network_cli.py

+21
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@
198198
response, for example I('re.I').
199199
vars:
200200
- name: ansible_terminal_stderr_re
201+
terminal_initial_newline:
202+
type: boolean
203+
description:
204+
- This boolean flag, that when set to I(True) will send newline on initial
205+
connection establishment to the remote device.
206+
- This can be useful for equipment which does not send an initial header until
207+
it receives some input, like Serial-to-SSH multiplexer hardware.
208+
default: false
209+
vars:
210+
- name: ansible_terminal_inital_newline
201211
terminal_initial_prompt:
202212
type: list
203213
elements: string
@@ -656,6 +666,10 @@ def _connect(self):
656666
"loaded terminal plugin for network_os %s" % self._network_os,
657667
)
658668

669+
terminal_initial_newline = (
670+
self.get_option("terminal_initial_newline") or self._terminal.terminal_initial_newline
671+
)
672+
659673
terminal_initial_prompt = (
660674
self.get_option("terminal_initial_prompt") or self._terminal.terminal_initial_prompt
661675
)
@@ -668,6 +682,13 @@ def _connect(self):
668682
)
669683
check_all = self.get_option("terminal_initial_prompt_checkall") or False
670684

685+
if terminal_initial_newline:
686+
self.send(
687+
command=b"",
688+
sendonly=True,
689+
newline=True
690+
)
691+
671692
self.receive(
672693
prompts=terminal_initial_prompt,
673694
answer=terminal_initial_answer,

plugins/plugin_utils/terminal_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class TerminalBase(TerminalBaseBase):
4040
re.compile(rb"\x1b\[m"), # ANSI reset code
4141
]
4242

43+
#: Send newline after initial session connection
44+
terminal_initial_newline = False
45+
4346
#: terminal initial prompt
4447
terminal_initial_prompt = None
4548

0 commit comments

Comments
 (0)