summaryrefslogtreecommitdiff
path: root/tasks/copy-rendered-templates-recursive.yml
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/copy-rendered-templates-recursive.yml')
-rw-r--r--tasks/copy-rendered-templates-recursive.yml58
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