Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
16 changes: 16 additions & 0 deletions roles/sync/files_sync/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
files_sync:
directories:
- source:
# Location of the files to sync from. DO NOT INCLUDE TRAILING SLASH!
files_dir: "/home/{{ deploy_user }}/shared/{{ project_name }}_prod/assets/{{ project_name }}_prod_default_public_files"
# Host that contains source files.
host: "localhost"
# Location on deploy server where source files get copied to first. NO TRAILING SLASH.
temp_dir: "/tmp"
# Used to create directory in /tmp.
build_id: mybuildprod
target:
# Location of the files to sync to. DO NOT INCLUDE TRAILING SLASH!
files_dir: "/home/{{ deploy_user }}/shared/{{ project_name }}_dev/assets/{{ project_name }}_dev_default_public_files"
build_id: mybuilddev
7 changes: 7 additions & 0 deletions roles/sync/files_sync/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Sync files.
include_tasks: "sync.yml"
with_items: "{{ files_sync.directories }}"
loop_control:
loop_var: files
run_once: true
21 changes: 21 additions & 0 deletions roles/sync/files_sync/tasks/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Create a temporary directory for source files on localhost.
ansible.builtin.file:
path: "{{ files.source.temp_dir }}/{{ files.source.build_id }}"
state: directory
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
delegate_to: localhost
run_once: true

- 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 }}/ {{ files.source.temp_dir }}/{{ files.source.build_id }}/"
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 {{ files.source.temp_dir }}/{{ files.source.build_id }}/ {{ ansible_play_hosts[0] }}:{{ files.target.files_dir }}/"
delegate_to: "localhost"
run_once: true