Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move plugin option settings. #44774

Merged
merged 2 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions bin/ansible-connection
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class ConnectionProcess(object):
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())
Expand Down
15 changes: 7 additions & 8 deletions lib/ansible/plugins/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):
self._local.set_options()

self._implementation_plugins = []
self._cached_variables = (None, None, None)

# reconstruct the socket_path and set instance values accordingly
self._ansible_playbook_pid = kwargs.get('ansible_playbook_pid')
Expand All @@ -317,6 +318,11 @@ def __getattr__(self, name):
return method
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))

def _connect(self):
for plugin in self._implementation_plugins:
plugin.set_options(*self._cached_variables)
self._cached_variables = (None, None, None)

def exec_command(self, cmd, in_data=None, sudoable=True):
return self._local.exec_command(cmd, in_data, sudoable)

Expand Down Expand Up @@ -344,14 +350,7 @@ def close(self):

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)
self._cached_variables = (task_keys, var_options, direct)

def _update_connection_state(self):
'''
Expand Down
9 changes: 6 additions & 3 deletions lib/ansible/plugins/connection/httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,8 @@ def _connect(self):

httpapi = httpapi_loader.get(self._network_os, self)
if httpapi:
display.vvvv('loaded API plugin for network_os %s' % self._network_os, host=self._play_context.remote_addr)
display.vvvv('loaded API plugin for network_os %s' % self._network_os, host=host)
self._implementation_plugins.append(httpapi)
httpapi.set_become(self._play_context)
httpapi.login(self.get_option('remote_user'), self.get_option('password'))
else:
raise AnsibleConnectionFailure('unable to load API plugin for network_os %s' % self._network_os)

Expand All @@ -220,6 +218,11 @@ def _connect(self):
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._connected = True

def close(self):
Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/plugins/connection/netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def _connect(self):
display.display('unable to load netconf plugin for network_os %s, falling back to default plugin' % self._network_os)
self._implementation_plugins.append(netconf)

super(Connection, self)._connect()

return 0, to_bytes(self._manager.session_id, errors='surrogate_or_strict'), b''

def close(self):
Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def _connect(self):
else:
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)

super(Connection, self)._connect()

self.receive(prompts=self._terminal.terminal_initial_prompt, answer=self._terminal.terminal_initial_answer,
newline=self._terminal.terminal_inital_prompt_newline)

Expand Down