From ea6ef3fae8741694fe70b5cf4b8566e816012f89 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 30 Jul 2018 21:53:44 -0700 Subject: [PATCH] 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 --- bin/ansible-connection | 5 +++++ lib/ansible/plugins/connection/__init__.py | 11 +++++++++++ lib/ansible/plugins/connection/network_cli.py | 1 - .../targets/eos_config/tests/cli/check_mode.yaml | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/ansible-connection b/bin/ansible-connection index 0d9ad17131..9b1ae2cd04 100755 --- a/bin/ansible-connection +++ b/bin/ansible-connection @@ -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()) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index e82f771b0d..d7e86e2510 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -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 diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 40235cc207..37c3c2ce74 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -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) diff --git a/test/integration/targets/eos_config/tests/cli/check_mode.yaml b/test/integration/targets/eos_config/tests/cli/check_mode.yaml index ddb3aa75ef..424b8bd15e 100644 --- a/test/integration/targets/eos_config/tests/cli/check_mode.yaml +++ b/test/integration/targets/eos_config/tests/cli/check_mode.yaml @@ -69,5 +69,6 @@ - assert: that: - "result.changed == true" + - "'session' not in result" - debug: msg="END cli/check_mode.yaml on connection={{ ansible_connection }}"