mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-11-22 23:20:27 +00:00
ACA-4558: synchronize: use ansible_host from play vars when absent from hostvars (#779)
* synchronize: use ansible_host from play vars when absent from hostvars The synchronize action plugin built the rsync/ssh destination exclusively from task_vars['hostvars'][inventory_hostname]. When ansible_host was set via play-level vars: rather than inventory/ group_vars/host_vars, it was absent from that snapshot and the plugin silently fell back to bare inventory_hostname, producing 'Host not found' errors when ansible_host differed from the inventory name. Fixes #469
This commit is contained in:
@@ -240,10 +240,17 @@ class ActionModule(ActionBase):
|
||||
src_host = '127.0.0.1'
|
||||
inventory_hostname = task_vars.get('inventory_hostname')
|
||||
dest_host_inventory_vars = task_vars['hostvars'].get(inventory_hostname)
|
||||
dest_host = dest_host_inventory_vars.get('ansible_host', inventory_hostname)
|
||||
# If the user did not set ansible_host, ansible fills it in with the address
|
||||
# of the delegate host when delegating, so only use ansible_host when not delegating.
|
||||
dest_host = ((task_vars.get('ansible_host') if delegate_to is None else None)
|
||||
or dest_host_inventory_vars.get('ansible_host')
|
||||
or inventory_hostname)
|
||||
if self._templar is not None:
|
||||
dest_host = self._templar.template(dest_host)
|
||||
|
||||
dest_host_ids = [hostid for hostid in (dest_host_inventory_vars.get('inventory_hostname'),
|
||||
dest_host_inventory_vars.get('ansible_host'))
|
||||
dest_host_inventory_vars.get('ansible_host'),
|
||||
dest_host)
|
||||
if hostid is not None]
|
||||
|
||||
localhost_ports = set()
|
||||
@@ -371,7 +378,10 @@ class ActionModule(ActionBase):
|
||||
src = self._process_origin(src_host, src, user)
|
||||
dest = self._process_remote(_tmp_args, dest_host, dest, user, inv_port in localhost_ports)
|
||||
|
||||
password = dest_host_inventory_vars.get('ansible_ssh_pass', None) or dest_host_inventory_vars.get('ansible_password', None)
|
||||
password = (task_vars.get('ansible_ssh_pass')
|
||||
or task_vars.get('ansible_password')
|
||||
or dest_host_inventory_vars.get('ansible_ssh_pass', None)
|
||||
or dest_host_inventory_vars.get('ansible_password', None))
|
||||
if self._templar is not None:
|
||||
password = self._templar.template(password)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user