Enable setting options for cliconf and other implementation plugins (if set to configurable) (#43368)

* Enable setting setting cliconf plugin options

Fixes #43367

* Add support to set configuration options for implementation plugins (eg: cliconf)
  from `ansible-connection`

* Fix CI failure
pull/43400/merge
Ganesh Nalawade 6 years ago committed by GitHub
parent d03b9eddf6
commit ea6ef3fae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -85,6 +85,11 @@ class ConnectionProcess(object):
ansible_playbook_pid=self._ansible_playbook_pid)
self.connection.set_options(var_options=variables)
self.connection._connect()
# implementation plugins are updated while connection initialization
if hasattr(self.connection, 'set_implementation_plugin_options'):
self.connection.set_implementation_plugin_options(var_options=variables)
self.connection._socket_path = self.socket_path
self.srv.register(self.connection)
messages.extend(sys.stdout.getvalue().splitlines())

@ -342,6 +342,17 @@ class NetworkConnectionBase(ConnectionBase):
self._connected = False
self._implementation_plugins = []
def set_options(self, task_keys=None, var_options=None, direct=None):
super(NetworkConnectionBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.set_implementation_plugin_options(task_keys=task_keys, var_options=var_options, direct=direct)
def set_implementation_plugin_options(self, task_keys=None, var_options=None, direct=None):
'''
initialize implementation plugin options
'''
for plugin in self._implementation_plugins:
plugin.set_options(task_keys=task_keys, var_options=var_options, direct=direct)
def _update_connection_state(self):
'''
Reconstruct the connection socket_path and check if it exists

@ -297,7 +297,6 @@ class Connection(NetworkConnectionBase):
if self.cliconf:
display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os, host=host)
self._implementation_plugins.append(self.cliconf)
self.cliconf.set_options()
else:
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)

@ -69,5 +69,6 @@
- assert:
that:
- "result.changed == true"
- "'session' not in result"
- debug: msg="END cli/check_mode.yaml on connection={{ ansible_connection }}"

Loading…
Cancel
Save