mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Move persistent connections to only use registered variables (#45616)
* Try to intuit proper plugins to send to ansible-connection * Move sub-plugins to init so that vars will be populated in executor * Fix connection unit tests
This commit is contained in:
@@ -176,7 +176,22 @@ class Connection(NetworkConnectionBase):
|
||||
self._url = None
|
||||
self._auth = None
|
||||
|
||||
if not self._network_os:
|
||||
if self._network_os:
|
||||
|
||||
self.httpapi = httpapi_loader.get(self._network_os, self)
|
||||
if self.httpapi:
|
||||
self._sub_plugins.append({'type': 'httpapi', 'name': self._network_os, 'obj': self.httpapi})
|
||||
display.vvvv('loaded API plugin for network_os %s' % self._network_os)
|
||||
else:
|
||||
raise AnsibleConnectionFailure('unable to load API plugin for network_os %s' % self._network_os)
|
||||
|
||||
self.cliconf = cliconf_loader.get(self._network_os, self)
|
||||
if self.cliconf:
|
||||
self._sub_plugins.append({'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf})
|
||||
display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os)
|
||||
else:
|
||||
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)
|
||||
else:
|
||||
raise AnsibleConnectionFailure(
|
||||
'Unable to automatically determine host network os. Please '
|
||||
'manually configure ansible_network_os value for this host'
|
||||
@@ -211,24 +226,8 @@ class Connection(NetworkConnectionBase):
|
||||
port = self.get_option('port') or (443 if protocol == 'https' else 80)
|
||||
self._url = '%s://%s:%s' % (protocol, host, port)
|
||||
|
||||
httpapi = httpapi_loader.get(self._network_os, self)
|
||||
if httpapi:
|
||||
display.vvvv('loaded API plugin for network_os %s' % self._network_os, host=host)
|
||||
self._implementation_plugins.append(httpapi)
|
||||
else:
|
||||
raise AnsibleConnectionFailure('unable to load API plugin for network_os %s' % self._network_os)
|
||||
|
||||
cliconf = cliconf_loader.get(self._network_os, self)
|
||||
if cliconf:
|
||||
display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os, host=host)
|
||||
self._implementation_plugins.append(cliconf)
|
||||
else:
|
||||
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)
|
||||
|
||||
super(Connection, self)._connect()
|
||||
|
||||
httpapi.set_become(self._play_context)
|
||||
httpapi.login(self.get_option('remote_user'), self.get_option('password'))
|
||||
self.httpapi.set_become(self._play_context)
|
||||
self.httpapi.login(self.get_option('remote_user'), self.get_option('password'))
|
||||
|
||||
self._connected = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user