From 68608a15a018d7fd2b80aed6ac6705e41811197e Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Fri, 2 Jun 2023 11:54:43 +0200 Subject: [PATCH] Optimize copy only mode --- tasks/present.yml | 73 +++----------------------------------- tasks/present_cp.yml | 21 +++++++++++ tasks/present_template.yml | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 69 deletions(-) create mode 100644 tasks/present_cp.yml create mode 100644 tasks/present_template.yml diff --git a/tasks/present.yml b/tasks/present.yml index c207213..2cbc4d7 100644 --- a/tasks/present.yml +++ b/tasks/present.yml @@ -1,70 +1,5 @@ --- - -- block: - - name: Create Temporary directory - tempfile: - state: directory - changed_when: false - register: temp_file - - name: Create directory structure - file: - state: directory - dest: '{{ temp_file.path }}/{{ item.path }}' - mode: "{{ item.mode }}" - changed_when: false - with_filetree: "{{ service_base }}/{{ service | mandatory }}" - when: item.state == 'directory' - loop_control: - label: '{{ item.path }}' - - name: Template Service Files - ansible.builtin.template: - src: "{{ item.src }}" - dest: "{{ temp_file.path }}/{{ item.path }}" - mode: "{{ item.mode }}" - force: true - trim_blocks: false - changed_when: false - with_filetree: "{{ service_base }}/{{ service | mandatory }}" - loop_control: - label: '{{ item.path }}' - when: item.state == 'file' and not disable_template - - name: Copy Service Files - ansible.builtin.copy: - src: "{{ item.src }}" - dest: "{{ temp_file.path }}/{{ item.path }}" - mode: "{{ item.mode }}" - force: true - changed_when: false - with_filetree: "{{ service_base }}/{{ service | mandatory }}" - loop_control: - label: '{{ item.path }}' - when: item.state == 'file' and disable_template - delegate_to: localhost - check_mode: no - -- name: Create Service Directory - file: - state: directory - path: "{{ compose_dir | mandatory }}" - -- name: Copy Compose files - become: false - ansible.posix.synchronize: - src: "{{ temp_file.path | mandatory }}/" - dest: "{{ service_dir | mandatory }}" - archive: false - checksum: true - delete: true - recursive: true - mode: push - owner: false - group: false - perms: false - use_ssh_args: true - register: compose_files - -- name: Delete temporary directory - ansible.builtin.file: - path: "{{ temp_file.path }}" - state: absent - changed_when: false +- include_tasks: present_cp.yml + when: disable_template +- include_tasks: present_template.yml + when: not disable_template diff --git a/tasks/present_cp.yml b/tasks/present_cp.yml new file mode 100644 index 0000000..4ff4d8a --- /dev/null +++ b/tasks/present_cp.yml @@ -0,0 +1,21 @@ +--- +- name: Create Service Directory + file: + state: directory + path: "{{ compose_dir | mandatory }}" + +- name: Copy Compose files + become: false + ansible.posix.synchronize: + src: "{{ service_base }}/{{ service | mandatory }}/" + dest: "{{ service_dir | mandatory }}" + archive: false + checksum: true + delete: true + recursive: true + mode: push + owner: false + group: false + perms: false + use_ssh_args: true + register: compose_files diff --git a/tasks/present_template.yml b/tasks/present_template.yml new file mode 100644 index 0000000..eca6524 --- /dev/null +++ b/tasks/present_template.yml @@ -0,0 +1,65 @@ +- name: Create Temporary directory + tempfile: + state: directory + changed_when: false + delegate_to: localhost + register: temp_file + +- block: + - name: Create Temporary directory + tempfile: + state: directory + changed_when: false + register: temp_file + - name: Create directory structure + file: + state: directory + dest: '{{ temp_file.path }}/{{ item.path }}' + mode: "{{ item.mode }}" + changed_when: false + with_filetree: "{{ service_base }}/{{ service | mandatory }}" + when: item.state == 'directory' + loop_control: + label: '{{ item.path }}' + - name: Template Service Files + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ temp_file.path }}/{{ item.path }}" + mode: "{{ item.mode }}" + force: true + trim_blocks: false + changed_when: false + with_filetree: "{{ service_base }}/{{ service | mandatory }}" + loop_control: + label: '{{ item.path }}' + when: item.state == 'file' + delegate_to: localhost + check_mode: no + +- name: Create Service Directory + file: + state: directory + path: "{{ compose_dir | mandatory }}" + +- name: Copy Compose files + become: false + ansible.posix.synchronize: + src: "{{ temp_file.path | mandatory }}/" + dest: "{{ service_dir | mandatory }}" + archive: false + checksum: true + delete: true + recursive: true + mode: push + owner: false + group: false + perms: false + use_ssh_args: true + register: compose_files + +- name: Delete temporary directory + ansible.builtin.file: + path: "{{ temp_file.path }}" + state: absent + changed_when: false + delegate_to: localhost