ansible.posix
ansible.posix copied to clipboard
synchronize connects to the wrong target
SUMMARY
When using inventory files with fantasy-hostnames and defining ansible_ssh_host the synchronize module wont connect to the correct ansible_ssh_host, but will try to connect to the hostname instead.
We see below that ansible tried to do a rsync <options> /root/host_files/DESTHOST/ ansible@DESTHOST:/var/ansible/host_files/
instead of rsync <options> /root/host_files/DESTHOST/ [email protected]:/var/ansible/host_files/
ISSUE TYPE
- Bug Report
COMPONENT NAME
synchronize
ANSIBLE VERSION
ansible [core 2.14.3]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT
Debian 12 stable + fasttrack.
STEPS TO REPRODUCE
ansible.inventory
[servers]
DESTHOST ansible_ssh_host="10.10.0.254"
the relevant task
- name: synchronize host's host_files-dir
synchronize:
src: "/root/host_files/{{inventory_hostname}}/"
dest: "/var/ansible/host_files/"
delete: yes
checksum: yes
recursive: yes
archive: no
EXPECTED RESULTS
Files getting synchronized.
Not: getting an exception that ansible cannot connect to the host it connected to successfully just before during the previous task.
ACTUAL RESULTS
We see below that ansible tried to do a rsync <options> /root/host_files/DESTHOST/ ansible@DESTHOST:/var/ansible/host_files/
instead of rsync <options> /root/host_files/DESTHOST/ [email protected]:/var/ansible/host_files/
fatal: [DESTHOST]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --delete-after --checksum --recursive --rsh='/usr/bin/ssh -S none -i /root/.ssh/id_ansible -o Port=22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path='sudo -u root rsync' --out-format='<<CHANGED>>%i %n%L' /root/host_files/DESTHOST/ ansible@DESTHOST:/var/ansible/host_files/", "msg": "ssh: Could not resolve hostname DESTHOST: Name or service not known\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: error in rsync protocol data stream (code 12) at io.c(231) [sender=3.2.7]\n", "rc": 12}
same issue here since update from Debian 11 to Debian 12. However, I get a slightly different error message:
ssh: connect to host <targetserver> port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]
if I add an entry for <targetserver> to /etc/hosts the transfer works flawlessly.
might be same issue as https://github.com/ansible-collections/ansible.posix/issues/469