Skip to content

Commit

Permalink
Add terminal_initial_newline to network_cli module
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
wrouesnel committed Oct 25, 2023
1 parent fada835 commit e7dd539
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 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_inital_newline
terminal_initial_prompt:
type: list
elements: string
Expand Down Expand Up @@ -656,6 +666,10 @@ 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 @@ -668,6 +682,13 @@ 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

0 comments on commit e7dd539

Please sign in to comment.