mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07: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:
parent
86c48205c4
commit
406b59aeba
10 changed files with 98 additions and 109 deletions
|
@ -842,17 +842,29 @@ class TaskExecutor:
|
|||
self._play_context.timeout = connection.get_option('persistent_command_timeout')
|
||||
display.vvvv('attempting to start connection', host=self._play_context.remote_addr)
|
||||
display.vvvv('using connection plugin %s' % connection.transport, host=self._play_context.remote_addr)
|
||||
# We don't need to send the entire contents of variables to ansible-connection
|
||||
filtered_vars = dict(
|
||||
(key, value) for key, value in variables.items()
|
||||
if key.startswith('ansible') and key != 'ansible_failed_task'
|
||||
)
|
||||
socket_path = self._start_connection(filtered_vars)
|
||||
|
||||
options = self._get_persistent_connection_options(connection, variables, templar)
|
||||
socket_path = self._start_connection(options)
|
||||
display.vvvv('local domain socket path is %s' % socket_path, host=self._play_context.remote_addr)
|
||||
setattr(connection, '_socket_path', socket_path)
|
||||
|
||||
return connection
|
||||
|
||||
def _get_persistent_connection_options(self, connection, variables, templar):
|
||||
final_vars = combine_vars(variables, variables.get('ansible_delegated_vars', dict()).get(self._task.delegate_to, dict()))
|
||||
|
||||
option_vars = C.config.get_plugin_vars('connection', connection._load_name)
|
||||
for plugin in connection._sub_plugins:
|
||||
if plugin['type'] != 'external':
|
||||
option_vars.extend(C.config.get_plugin_vars(plugin['type'], plugin['name']))
|
||||
|
||||
options = {}
|
||||
for k in option_vars:
|
||||
if k in final_vars:
|
||||
options[k] = templar.template(final_vars[k])
|
||||
|
||||
return options
|
||||
|
||||
def _set_connection_options(self, variables, templar):
|
||||
|
||||
# Keep the pre-delegate values for these keys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue