From 35b484a8d4c13168d2c8d945d00c2eecd07c47a2 Mon Sep 17 00:00:00 2001 From: Qwinci Date: Fri, 14 Mar 2025 11:49:42 +0200 Subject: [PATCH] Use ip's when syncing from production hosts Use production host from the inventory with a different hostname `.prod` when syncing to avoid dns/Ansible issues where the files would be synced from the target machine instead of the production machine. This requires that the production ip's are specified in the inventory under the .prod hostname with `ansible_host` and possibly the user with `ansible_user` if running against Vagrant VM where the used user doesn't match the one used on the production machine. --- tasks/control_host_sync.yml | 2 +- tasks/target_sync.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/control_host_sync.yml b/tasks/control_host_sync.yml index 18e2879..4c74926 100644 --- a/tasks/control_host_sync.yml +++ b/tasks/control_host_sync.yml @@ -23,7 +23,7 @@ rsync --delay-updates --compress --archive --out-format='{{changed_marker}}%i %n%L' {{ item[1].rsync_params|default('') }} - {{hostvars[item.0.source].ansible_ssh_user|default(ansible_ssh_user)}}@{{item[0].source}}:{{item[1].source}} + {{hostvars[item.0.source + '.prod'].ansible_user|default(ansible_user)}}@{{hostvars[item[0].source + '.prod'].ansible_host}}:{{item[1].source}} {{ file_sync_local_dir }}/{{item[0].source}}{{ item[1].source }} register: rsync_in_result delegate_to: localhost diff --git a/tasks/target_sync.yml b/tasks/target_sync.yml index 8f738d0..1f6fcb5 100644 --- a/tasks/target_sync.yml +++ b/tasks/target_sync.yml @@ -12,7 +12,7 @@ rsync --delay-updates --compress --archive --out-format='{{changed_marker}}%i %n%L' {{ item[1].rsync_params|default('') }} - {{hostvars[item.0.source].ansible_ssh_user|default(ansible_ssh_user)}}@{{item[0].source}}:{{item[1].source}} {{ item[1].target }} + {{hostvars[item.0.source + '.prod'].ansible_user|default(ansible_user)}}@{{hostvars[item[0].source + '.prod'].ansible_host}}:{{item[1].source}} {{ item[1].target }} register: rsync_in_result changed_when: "'{{changed_marker}}' in rsync_in_result.stdout" with_subelements: