From b8ffbfe27eae919750ef4d3facf02393d1004287 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Wed, 7 May 2025 18:10:57 -0700 Subject: .git was corrupted on the machine i worked on these many commits. so here it is all at once :P --- tasks/copy-rendered-templates-recursive.yml | 60 ++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'tasks/copy-rendered-templates-recursive.yml') diff --git a/tasks/copy-rendered-templates-recursive.yml b/tasks/copy-rendered-templates-recursive.yml index 0733493..2b83834 100644 --- a/tasks/copy-rendered-templates-recursive.yml +++ b/tasks/copy-rendered-templates-recursive.yml @@ -7,7 +7,7 @@ state: directory register: tempdir -- name: Ensure parent directories exist for rendered templates +- name: Ensure parent directories exist for all files delegate_to: localhost become: false ansible.builtin.file: @@ -17,36 +17,69 @@ with_filetree: "{{ render_dir }}" when: item.state == "file" -- name: Recursively render templates +- name: Check if each file is text or binary + delegate_to: localhost + become: false + ansible.builtin.command: + cmd: file --mime-type "{{ item.src }}" + register: file_type_check + changed_when: false + with_filetree: "{{ render_dir }}" + when: item.state == "file" + loop_control: + label: "{{ item.path }}" + +- name: Separate text and binary files + set_fact: + text_files: >- + {{ + file_type_check.results + | selectattr('stdout', 'defined') + | selectattr('stdout', 'search', '^.*: text/') + | map(attribute='item') + | list + }} + binary_files: >- + {{ + file_type_check.results + | selectattr('stdout', 'defined') + | rejectattr('stdout', 'search', '^.*: text/') + | map(attribute='item') + | list + }} + +- name: Render templates (text files only) 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" + loop: "{{ text_files }}" -- name: Sync rendered templates to remote host +- name: Copy binary files directly delegate_to: localhost become: false - ansible.builtin.synchronize: - src: "{{ tempdir.path }}/" - dest: "{{ tempdir.path }}/" + ansible.builtin.copy: + src: "{{ item.src }}" + dest: "{{ tempdir.path }}/{{ item.path }}" + mode: "{{ mode | default('0644') }}" + loop: "{{ binary_files }}" -- name: Remove local temporary directory +- name: Sync rendered and copied files to remote host delegate_to: localhost become: false - ansible.builtin.file: - path: "{{ tempdir.path }}" - state: absent + ansible.builtin.synchronize: + src: "{{ tempdir.path }}/" + dest: "{{ tempdir.path }}/" + recursive: true - name: Ensure destination exists ansible.builtin.file: path: "{{ destination_dir }}" state: directory -- name: Update remote files +- name: Copy files to final destination ansible.builtin.command: cmd: bash -c 'cp -r {{ tempdir.path }}/* {{ destination_dir }}/' @@ -61,3 +94,4 @@ ansible.builtin.file: path: "{{ tempdir.path }}" state: absent + -- cgit v1.2.3-70-g09d2