Added tar option to preserve metadata of existing fetch_dir

Added tar option to allow the current user to unpack local
or downloaded data (from swift) into ceph-ansible/fetch_dir,
preserving the existing metadata.
Added also a "/*" as trailing character on the *path field* of
the *archive* ansible task to create a tar.gz containing all
the fetch_dir content whithout including the parent directory
in the resulting path: in this way we should be able to avoid
nested fetch_dir.

1. Added a step to fix broken environment excluding the nested
fetch_dir from the archive sections;

2. Added a new task to delete from filesystem the nested
section to make everything clean: this task is executed
according to the output of the previous one (the archive task).

Change-Id: I45c394bd6b5c09730399202b476ed913e8f334c0
Related-Bug: 1816094
This commit is contained in:
fpantano 2019-02-18 13:39:10 +01:00
parent 26a3d4336c
commit 548f54b39d

View File

@ -517,7 +517,7 @@ outputs:
ignore_errors: True
- name: untar local backup of ceph-ansible fetch directory
# unarchive module hit https://github.com/ansible/ansible/issues/35645
shell: "/usr/bin/gtar --gzip --extract --file {{local_ceph_ansible_fetch_directory_backup}}/{{ceph_ansible_tarball_name}} -C {{playbook_dir}}/ceph-ansible/fetch_dir"
shell: "/usr/bin/gtar --gzip --extract --no-overwrite-dir --file {{local_ceph_ansible_fetch_directory_backup}}/{{ceph_ansible_tarball_name}} -C {{playbook_dir}}/ceph-ansible/fetch_dir"
when: local_backup_file.stat.exists == True
when: local_ceph_ansible_fetch_directory_backup != ""
- block: # swift backup
@ -540,7 +540,7 @@ outputs:
- curl_get_http_status.stdout != "404" # new deployment
- name: unpack downloaded ceph-ansible fetch tarball to fetch directory
# unarchive module hit https://github.com/ansible/ansible/issues/35645
shell: "/usr/bin/gtar --gzip --extract --file /tmp/{{old_ceph_ansible_tarball_name}} -C {{playbook_dir}}/ceph-ansible/fetch_dir"
shell: "/usr/bin/gtar --gzip --extract --no-overwrite-dir --file /tmp/{{old_ceph_ansible_tarball_name}} -C {{playbook_dir}}/ceph-ansible/fetch_dir"
when:
- curl_get_http_status.changed
- curl_get_http_status.stdout == "200"
@ -606,14 +606,20 @@ outputs:
- outputs.rc != 0
- name: create ceph-ansible fetch directory tarball in local backup
archive:
path: "{{playbook_dir}}/ceph-ansible/fetch_dir"
path: "{{playbook_dir}}/ceph-ansible/fetch_dir/*"
dest: "{{local_ceph_ansible_fetch_directory_backup}}/{{ceph_ansible_tarball_name}}"
exclude_path:
- '{{playbook_dir}}/ceph-ansible/fetch_dir/fetch_dir'
register: nested
when: local_ceph_ansible_fetch_directory_backup != ""
- block: # swift backup
- name: create temporary ceph-ansible fetch directory tarball for swift backup
archive:
path: "{{playbook_dir}}/ceph-ansible/fetch_dir"
path: "{{playbook_dir}}/ceph-ansible/fetch_dir/*"
dest: "/tmp/{{new_ceph_ansible_tarball_name}}"
exclude_path:
- '{{playbook_dir}}/ceph-ansible/fetch_dir/fetch_dir'
register: nested
- name: backup temporary ceph-ansible fetch directory tarball in swift
shell: "curl -s -o /dev/null -w '%{http_code}' -X PUT -T /tmp/{{new_ceph_ansible_tarball_name}} \"{{ swift_put_url }}\""
register: curl_put_http_status
@ -631,6 +637,14 @@ outputs:
when: (curl_put_http_status.changed and (curl_put_http_status.stdout == "200" or
curl_put_http_status.stdout == "201"))
when: local_ceph_ansible_fetch_directory_backup == ""
- name: remove nested broken path if exist
file:
state: absent
path: "{{ item }}"
recurse: no
with_items:
- '{{ nested.missing }}'
when: (nested.missing|default([])|length > 0)
external_update_tasks:
- when: step|int == 0
tags: ceph