Merge "Make transfer and persist modules, trailing slash insensitive."

This commit is contained in:
Zuul 2019-02-07 04:52:57 +00:00 committed by Gerrit Code Review
commit 2a50d30da0
3 changed files with 32 additions and 12 deletions

View File

@ -13,17 +13,22 @@
prefix: ansible.tripleo-persist. prefix: ansible.tripleo-persist.
register: tripleo_persist_tempfile register: tripleo_persist_tempfile
- name: make sure we don't have a trailing forward slash
set_fact:
tripleo_persist_dir_safe: "{{tripleo_persist_dir|regex_replace('\\/$', '')}}"
cacheable: no
# Using the "archive" module lists lists all tarred files in module # Using the "archive" module lists lists all tarred files in module
# output, if there's too many files, it can crash ansible even with # output, if there's too many files, it can crash ansible even with
# "no_log: true". # "no_log: true".
- name: create the archive - name: create the archive
shell: | shell: |
tar -czf "{{tripleo_persist_tempfile.path}}" -C "{{tripleo_persist_dir|dirname}}" "{{tripleo_persist_dir|basename}}" tar -czf "{{tripleo_persist_tempfile.path}}" -C "{{tripleo_persist_dir_safe|dirname}}" "{{tripleo_persist_dir_safe|basename}}"
- name: fetch the archive - name: fetch the archive
fetch: fetch:
src: "{{tripleo_persist_tempfile.path}}" src: "{{tripleo_persist_tempfile.path}}"
dest: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir}}.tar.gz" dest: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir_safe}}.tar.gz"
flat: yes flat: yes
- name: remove tempfile - name: remove tempfile

View File

@ -1,9 +1,14 @@
- name: make sure we don't have a trailing forward slash
set_fact:
tripleo_persist_dir_safe: "{{tripleo_persist_dir|regex_replace('\\/$', '')}}"
cacheable: no
- name: make sure the parent directory is present - name: make sure the parent directory is present
file: file:
path: "{{tripleo_persist_dir|dirname}}" path: "{{tripleo_persist_dir_safe|dirname}}"
state: directory state: directory
- name: push and extract the archive - name: push and extract the archive
unarchive: unarchive:
src: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir}}.tar.gz" src: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir_safe}}.tar.gz"
dest: "{{tripleo_persist_dir|dirname}}" dest: "{{tripleo_persist_dir_safe|dirname}}"

View File

@ -1,3 +1,13 @@
- name: make sure we don't have a trailing forward slash in the src
set_fact:
tripleo_transfer_src_dir_safe: "{{tripleo_transfer_src_dir|regex_replace('\\/$', '')}}"
cacheable: no
- name: make sure we don't have a trailing forward slash in the dst
set_fact:
tripleo_transfer_dest_dir_safe: "{{tripleo_transfer_dest_dir|regex_replace('\\/$', '')}}"
cacheable: no
- name: ensure local storage directory exists and has correct permissions - name: ensure local storage directory exists and has correct permissions
file: file:
path: "{{tripleo_transfer_storage_root_dir}}" path: "{{tripleo_transfer_storage_root_dir}}"
@ -20,14 +30,14 @@
# "no_log: true". # "no_log: true".
- name: create the archive - name: create the archive
shell: | shell: |
tar --transform "s|^{{tripleo_transfer_src_dir|basename}}|{{tripleo_transfer_dest_dir|basename}}|" -czf "{{tripleo_transfer_tempfile.path}}" -C "{{tripleo_transfer_src_dir|dirname}}" "{{tripleo_transfer_src_dir|basename}}" tar --transform "s|^{{tripleo_transfer_src_dir_safe|basename}}|{{tripleo_transfer_dest_dir_safe|basename}}|" -czf "{{tripleo_transfer_tempfile.path}}" -C "{{tripleo_transfer_src_dir_safe|dirname}}" "{{tripleo_transfer_src_dir_safe|basename}}"
become: "{{tripleo_transfer_src_become}}" become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}" delegate_to: "{{tripleo_transfer_src_host}}"
- name: fetch the archive - name: fetch the archive
fetch: fetch:
src: "{{tripleo_transfer_tempfile.path}}" src: "{{tripleo_transfer_tempfile.path}}"
dest: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz" dest: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir_safe}}.tar.gz"
flat: yes flat: yes
become: "{{tripleo_transfer_src_become}}" become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}" delegate_to: "{{tripleo_transfer_src_host}}"
@ -41,7 +51,7 @@
- name: wipe the destination directory - name: wipe the destination directory
file: file:
path: "{{tripleo_transfer_dest_dir}}" path: "{{tripleo_transfer_dest_dir_safe}}"
state: absent state: absent
become: "{{tripleo_transfer_dest_become}}" become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}" delegate_to: "{{tripleo_transfer_dest_host}}"
@ -49,19 +59,19 @@
- name: make sure the destination parent directory is present - name: make sure the destination parent directory is present
file: file:
path: "{{tripleo_transfer_dest_dir|dirname}}" path: "{{tripleo_transfer_dest_dir_safe|dirname}}"
state: directory state: directory
become: "{{tripleo_transfer_dest_become}}" become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}" delegate_to: "{{tripleo_transfer_dest_host}}"
- name: push and extract the archive - name: push and extract the archive
unarchive: unarchive:
src: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz" src: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir_safe}}.tar.gz"
dest: "{{tripleo_transfer_dest_dir|dirname}}" dest: "{{tripleo_transfer_dest_dir_safe|dirname}}"
become: "{{tripleo_transfer_dest_become}}" become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}" delegate_to: "{{tripleo_transfer_dest_host}}"
- name: remove the local archive - name: remove the local archive
file: file:
path: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz" path: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir_safe}}.tar.gz"
state: absent state: absent