ansible: fix non-action connection instantiation.

e.g. by synchronize module.
pull/372/head
David Wilson 6 years ago
parent 705d77a9be
commit b254eb3399

@ -333,14 +333,15 @@ def config_from_play_context(transport, inventory_name, connection):
'password': connection._play_context.password, 'password': connection._play_context.password,
'port': connection._play_context.port, 'port': connection._play_context.port,
'python_path': parse_python_path( 'python_path': parse_python_path(
connection.task_vars.get('ansible_python_interpreter', connection.get_task_var('ansible_python_interpreter',
'/usr/bin/python') default='/usr/bin/python')
), ),
'private_key_file': connection._play_context.private_key_file, 'private_key_file': connection._play_context.private_key_file,
'ssh_executable': connection._play_context.ssh_executable, 'ssh_executable': connection._play_context.ssh_executable,
'timeout': connection._play_context.timeout, 'timeout': connection._play_context.timeout,
'ansible_ssh_timeout': 'ansible_ssh_timeout':
connection.task_vars.get('ansible_ssh_timeout', C.DEFAULT_TIMEOUT), connection.get_task_var('ansible_ssh_timeout',
default=C.DEFAULT_TIMEOUT),
'ssh_args': [ 'ssh_args': [
mitogen.core.to_text(term) mitogen.core.to_text(term)
for s in ( for s in (
@ -360,17 +361,17 @@ def config_from_play_context(transport, inventory_name, connection):
for term in ansible.utils.shlex.shlex_split(s or '') for term in ansible.utils.shlex.shlex_split(s or '')
], ],
'mitogen_via': 'mitogen_via':
connection.task_vars.get('mitogen_via'), connection.get_task_var('mitogen_via'),
'mitogen_kind': 'mitogen_kind':
connection.task_vars.get('mitogen_kind'), connection.get_task_var('mitogen_kind'),
'mitogen_docker_path': 'mitogen_docker_path':
connection.task_vars.get('mitogen_docker_path'), connection.get_task_var('mitogen_docker_path'),
'mitogen_lxc_info_path': 'mitogen_lxc_info_path':
connection.task_vars.get('mitogen_lxc_info_path'), connection.get_task_var('mitogen_lxc_info_path'),
'mitogen_machinectl_path': 'mitogen_machinectl_path':
connection.task_vars.get('mitogen_machinectl_path'), connection.get_task_var('mitogen_machinectl_path'),
'mitogen_ssh_debug_level': 'mitogen_ssh_debug_level':
connection.task_vars.get('mitogen_ssh_debug_level'), connection.get_task_var('mitogen_ssh_debug_level'),
} }
@ -439,8 +440,11 @@ class Connection(ansible.plugins.connection.ConnectionBase):
# the case of the synchronize module. # the case of the synchronize module.
# #
#: Set to the host name as it appears in inventory by on_action_run().
inventory_hostname = None
#: Set to task_vars by on_action_run(). #: Set to task_vars by on_action_run().
task_vars = None _task_vars = None
#: Set to 'hostvars' by on_action_run() #: Set to 'hostvars' by on_action_run()
host_vars = None host_vars = None
@ -485,12 +489,17 @@ class Connection(ansible.plugins.connection.ConnectionBase):
Loader base directory; see :attr:`loader_basedir`. Loader base directory; see :attr:`loader_basedir`.
""" """
self.inventory_hostname = task_vars['inventory_hostname'] self.inventory_hostname = task_vars['inventory_hostname']
self.task_vars = task_vars self._task_vars = task_vars
self.host_vars = task_vars['hostvars'] self.host_vars = task_vars['hostvars']
self.delegate_to_hostname = delegate_to_hostname self.delegate_to_hostname = delegate_to_hostname
self.loader_basedir = loader_basedir self.loader_basedir = loader_basedir
self.close(new_task=True) self.close(new_task=True)
def get_task_var(self, key, default=None):
if self._task_vars and key in self._task_vars:
return self._task_vars[key]
return default
@property @property
def homedir(self): def homedir(self):
self._connect() self._connect()

Loading…
Cancel
Save