Optimize copy only mode

This commit is contained in:
Tobias Manske 2023-06-02 11:54:43 +02:00
parent 4616ae691d
commit 68608a15a0
Signed by: tobias
GPG Key ID: 9164B527694A0709
3 changed files with 90 additions and 69 deletions

View File

@ -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

21
tasks/present_cp.yml Normal file
View File

@ -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

View File

@ -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