mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-09 17:59:09 -07:00
adds feature to try to auto determine network_os (#18674)
This updates the network_cli connection plugin to attempt to automatically determine the remote device os. The device network os discovery can be overridden by setting the ansible_network_os value.
This commit is contained in:
parent
6fe9a5e40c
commit
8137c7207d
8 changed files with 56 additions and 7 deletions
|
@ -39,14 +39,8 @@ class Connection(_Connection):
|
|||
def __init__(self, play_context, new_stdin, *args, **kwargs):
|
||||
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
||||
|
||||
assert self._play_context.network_os, 'ansible_network_os must be set'
|
||||
|
||||
self._terminal = terminal_loader.get(self._play_context.network_os, self)
|
||||
if not self._terminal:
|
||||
raise AnsibleConnectionFailure('network os %s is not supported' % self._play_context.network_os)
|
||||
|
||||
self._terminal = None
|
||||
self._shell = None
|
||||
|
||||
self._matched_prompt = None
|
||||
self._matched_pattern = None
|
||||
self._last_response = None
|
||||
|
@ -64,6 +58,24 @@ class Connection(_Connection):
|
|||
|
||||
def _connect(self):
|
||||
super(Connection, self)._connect()
|
||||
|
||||
network_os = self._play_context.network_os
|
||||
if not network_os:
|
||||
for cls in terminal_loader.all(class_only=True):
|
||||
network_os = cls.guess_network_os(self.ssh)
|
||||
if network_os:
|
||||
break
|
||||
|
||||
if not network_os:
|
||||
raise AnsibleConnectionFailure(
|
||||
'unable to determine device network os. Please configure '
|
||||
'ansible_network_os value'
|
||||
)
|
||||
|
||||
self._terminal = terminal_loader.get(network_os, self)
|
||||
if not self._terminal:
|
||||
raise AnsibleConnectionFailure('network os %s is not supported' % network_os)
|
||||
|
||||
return (0, 'connected', '')
|
||||
|
||||
def open_shell(self, timeout=10):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue