Skip to content

Commit 79883ce

Browse files
committed
Use ip's when syncing from production hosts
Use production host from the inventory with a different hostname `<hostname>.prod` when creating the dump and syncing to avoid dns/Ansible issues where the dump would be created on 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.
1 parent f294e23 commit 79883ce

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tasks/control_host_sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
command: >
55
rsync {{ '--remove-source-files' if mysql_sync_delete_dump is defined else '' }} --delay-updates --compress --archive
66
--out-format='{{changed_marker}}%i %n%L'
7-
{{hostvars[item.source].ansible_ssh_user|default(ansible_ssh_user)}}@{{item.source}}:{{ mysql_sync_source_dump_dir }}/{{ item.database }}.sql.compressed
7+
{{hostvars[item.source + '.prod'].ansible_user|default(ansible_user)}}@{{hostvars[item.source + '.prod'].ansible_host}}:{{ mysql_sync_source_dump_dir }}/{{ item.database }}.sql.compressed
88
{{ mysql_sync_dump_dir }}/{{ item.database }}.sql.compressed
99
delegate_to: localhost
1010
with_items: "{{ mysql_sync_config }}"

tasks/sql_dump.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
mysqldump {{ item.database }}
66
--no-data
77
> {{ mysql_sync_source_dump_dir }}/{{ item.database }}_struc.sql
8-
delegate_to: "{{ item.source }}"
8+
delegate_to: "{{ item.source }}.prod"
99
remote_user: "{{ mysql_sync_remote_user }}"
1010
with_items: "{{ mysql_sync_config }}"
1111
check_mode: no
@@ -19,7 +19,7 @@
1919
{{ item.skip_tables|default('')|join(' --ignore-table ' ~ item.database ~ '.')|regex_replace('^(.)', ' --ignore-table ' ~ item.database ~ '.' ~ '\\1')}};
2020
} | {{ mysql_sync_compress_cmd | default(mysql_sync_default_compress_commands[mysql_sync_compress_method]['compress_cmd']) }}
2121
{{ mysql_sync_compress_args | default('') }} > {{ mysql_sync_source_dump_dir }}/{{ item.database }}.sql.compressed
22-
delegate_to: "{{ item.source }}"
22+
delegate_to: "{{ item.source }}.prod"
2323
remote_user: "{{ mysql_sync_remote_user }}"
2424
with_items: "{{ mysql_sync_config }}"
2525
check_mode: no

tasks/target_sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
- name: Copy files from source to target.
4-
shell: "rsync {{ '--remove-source-files' if mysql_sync_delete_dump is defined else '' }} --delay-updates --compress --archive --out-format='{{changed_marker}}%i %n%L' {{hostvars[item.source].ansible_ssh_user|default(ansible_ssh_user)}}@{{item.source}}:{{ mysql_sync_source_dump_dir }}/{{ item.database }}.sql.compressed {{ mysql_sync_dump_dir }}/{{ item.database }}.sql.compressed"
4+
shell: "rsync {{ '--remove-source-files' if mysql_sync_delete_dump is defined else '' }} --delay-updates --compress --archive --out-format='{{changed_marker}}%i %n%L' {{hostvars[item.source + '.prod'].ansible_user|default(ansible_user)}}@{{hostvars[item.source + '.prod'].ansible_host}}:{{ mysql_sync_source_dump_dir }}/{{ item.database }}.sql.compressed {{ mysql_sync_dump_dir }}/{{ item.database }}.sql.compressed"
55
check_mode: no
66
with_items: "{{ mysql_sync_config }}"
77

0 commit comments

Comments
 (0)