Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
mysql_sync:
mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here
cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes
databases:
- source:
# Name of the database to take a dump from.
Expand Down
20 changes: 17 additions & 3 deletions roles/sync/database_sync/database_sync-mysql/tasks/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
delegate_to: localhost
when: database.target.type == 'rolling'

- name: Register target database name.
- name: Register target rolling database name.
ansible.builtin.set_fact:
mysql_sync_target_database: "{{ database.target.database }}_{{ mysql_sync_target_build_number.stdout }}"
when: database.target.type == 'rolling'

- name: Register target database name.
- name: Register target static database name.
ansible.builtin.set_fact:
mysql_sync_target_database: "{{ database.target.database }}"
when: not database.target.type == 'rolling'
Expand Down Expand Up @@ -139,11 +139,25 @@
args:
executable: /bin/bash

- name: Remove tmp dump file.
- name: Delete temporary dump file on target.
ansible.builtin.file:
path: "{{ mysql_sync_target_dump_path }}"
state: absent

- name: Delete temporary dump file on source.
ansible.builtin.file:
path: "{{ mysql_sync_source_dump_path }}"
state: absent
delegate_to: "{{ database.source.host }}"

- name: Delete temporary dump file on deploy server.
ansible.builtin.file:
path: "{{ _ce_deploy_build_tmp_dir }}/{{ database.target.database }}.sql.bz2"
state: absent
delegate_to: localhost
when:
- mysql_sync.cleanup

- name: Enable all autoscale processes on source ASG.
ansible.builtin.command: >
aws autoscaling resume-processes --auto-scaling-group-name {{ database.source.asg }} --region {{ mysql_sync_source_database_host_info.ansible_facts.ansible_ec2_instance_identity_document_region }}
Expand Down
3 changes: 3 additions & 0 deletions roles/sync/files_sync/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
files_sync:
unique_workspace: false # set to true to grab a complete full set of files every sync
# Generally speaking you will *not* want to clean up after file syncs, as leaving the files there makes the next rsync far quicker.
cleanup: false # set to true to delete the synced files after a sync
directories:
- source:
# Location of the files to sync from. DO NOT INCLUDE TRAILING SLASH!
Expand Down
17 changes: 15 additions & 2 deletions roles/sync/files_sync/tasks/sync.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---
- name: Register file sync location.
ansible.builtin.set_fact:
file_sync_path: "{{ files.source.temp_dir }}/{{ files.source.build_id }}"

- name: Register unique file sync location.
ansible.builtin.set_fact:
file_sync_path: "{{ files.source.temp_dir }}/{{ files.source.build_id }}_{{ build_number }}"
when: files_sync.unique_workspace

- name: Create a temporary directory for source files on localhost.
ansible.builtin.file:
Expand All @@ -15,11 +20,19 @@
- name: Copy the source files onto the deploy server.
ansible.builtin.command:
cmd: "rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -aHPv {{ files.source.host }}:{{ files.source.files_dir }}/ {{ file_sync_path }}/"
delegate_to: "localhost"
delegate_to: localhost
run_once: true

- name: Copy the source files from the deploy server onto the destination server.
ansible.builtin.command:
cmd: "rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -aHPv {{ file_sync_path }}/ {{ ansible_play_hosts[0] }}:{{ files.target.files_dir }}/"
delegate_to: "localhost"
delegate_to: localhost
run_once: true

- name: Delete synced files on deploy server.
ansible.builtin.file:
path: "{{ file_sync_path }}"
state: absent
delegate_to: localhost
when:
- files_sync.cleanup