tripleo-ansible/tripleo_ansible/roles/tripleo-ceph-fetch-dir/tasks/backup_and_clean.yml

69 lines
2.8 KiB
YAML

---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: register contents of fetch_directory after ceph-ansible run
find:
paths: "{{ playbook_dir }}/ceph-ansible/fetch_dir/"
recurse: true
register: ceph_ansible_fetch_dir_contents
# backup to local directory
- name: create ceph-ansible fetch directory tarball in local backup
archive:
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'
when:
- local_ceph_ansible_fetch_directory_backup | length > 0
- ceph_ansible_fetch_dir_contents.matched|int != 0
# backup to swift
- when:
- local_ceph_ansible_fetch_directory_backup | length == 0
- ceph_ansible_fetch_dir_contents.matched|int != 0
block:
- name: create temporary ceph-ansible fetch directory tarball for swift backup
archive:
path: "{{ playbook_dir }}/ceph-ansible/fetch_dir/*"
dest: "/tmp/{{ new_ceph_ansible_tarball_name }}"
exclude_path:
- '{{ playbook_dir }}/ceph-ansible/fetch_dir/fetch_dir'
- 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
- fail:
msg: 'Received HTTP: {{ curl_put_http_status.stdout }} when attempting to PUT to {{ swift_put_url }}'
name: ensure we were able to backup temporary fetch directory to swift
when:
- curl_put_http_status is changed
- curl_put_http_status.stdout != "200"
- curl_put_http_status.stdout != "201"
- name: clean temporary fetch directory after swift backup
file:
path: "/tmp/{{ new_ceph_ansible_tarball_name }}"
state: absent
when: (curl_put_http_status is changed and
(curl_put_http_status.stdout == "200" or
curl_put_http_status.stdout == "201"))
# remove copy of fetchdir in case another user unpacks it (LP #1823229)
- name: Remove ceph-ansible fetch directory
become: true
file:
path: "{{ playbook_dir }}/ceph-ansible/fetch_dir/"
state: absent