diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-04-27 21:15:30 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-04-27 21:25:52 -0700 |
| commit | daef0cf448af17357b552245f39067a9d340ce3d (patch) | |
| tree | f65a660f7232f057b0c14e477c166006bfb83f87 /tasks/copy-rendered-templates-recursive.yml | |
| parent | 1dcdfe34a74708f88aad68af965f4bb5c79adff1 (diff) | |
| download | oldinfra-daef0cf448af17357b552245f39067a9d340ce3d.tar.gz oldinfra-daef0cf448af17357b552245f39067a9d340ce3d.zip | |
Waow
Diffstat (limited to 'tasks/copy-rendered-templates-recursive.yml')
| -rw-r--r-- | tasks/copy-rendered-templates-recursive.yml | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tasks/copy-rendered-templates-recursive.yml b/tasks/copy-rendered-templates-recursive.yml new file mode 100644 index 0000000..e47c39c --- /dev/null +++ b/tasks/copy-rendered-templates-recursive.yml @@ -0,0 +1,58 @@ +--- + +- name: Create temporary directory on localhost + delegate_to: localhost + become: false + ansible.builtin.tempfile: + state: directory + register: tempdir + +- name: Ensure parent directories exist for rendered templates + delegate_to: localhost + become: false + ansible.builtin.file: + path: "{{ tempdir.path }}/{{ item.path | dirname }}" + state: directory + mode: "{{ mode | default('0755') }}" + with_filetree: "{{ render_dir }}" + when: item.state == "file" + +- name: Recursively render templates + delegate_to: localhost + become: false + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ tempdir.path }}/{{ item.path }}" + mode: "{{ mode | default('0755') }}" + with_filetree: "{{ render_dir }}" + when: item.state == "file" + +- name: Sync rendered templates to remote host + delegate_to: localhost + become: false + ansible.builtin.synchronize: + src: "{{ tempdir.path }}/" + dest: "{{ tempdir.path }}/" + +- name: Remove local temporary directory + delegate_to: localhost + become: false + ansible.builtin.file: + path: "{{ tempdir.path }}" + state: absent + +- name: Update remote files + ansible.builtin.command: + cmd: bash -c 'cp -r {{ tempdir.path }}/* {{ destination_dir }}/' + +- name: Remove local temporary directory + delegate_to: localhost + become: false + ansible.builtin.file: + path: "{{ tempdir.path }}" + state: absent + +- name: Remove remote temporary directory + ansible.builtin.file: + path: "{{ tempdir.path }}" + state: absent |
