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

71 lines
3.2 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.
# local backup
- when: local_ceph_ansible_fetch_directory_backup | length > 0
block:
- name: look for requested ceph-ansible fetch directory for local backup
stat: path="{{ local_ceph_ansible_fetch_directory_backup }}"
register: local_backup_directory
ignore_errors: true
- name: autocreate new directory for ceph-ansible fetch directory backup
become: true
file:
path: "{{ local_ceph_ansible_fetch_directory_backup }}"
state: directory
owner: "{{ ansible_user }}"
mode: 0700
when: not local_backup_directory.stat.exists
- name: look for tarball of ceph-ansible fetch directory in local backup
stat: path="{{ local_ceph_ansible_fetch_directory_backup }}/{{ ceph_ansible_tarball_name }}"
register: local_backup_file
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
when: local_backup_file.stat.exists
# swift backup
- when: local_ceph_ansible_fetch_directory_backup | length == 0
block:
- name: attempt download of fetch directory tarball from swift backup
shell: "curl -s -o /tmp/{{ old_ceph_ansible_tarball_name }} -w '%{http_code}' -X GET \"{{ swift_get_url }}\""
register: curl_get_http_status
ignore_errors: true
- name: ensure we create a new fetch_directory or use the old fetch_directory
fail:
msg: "Received HTTP: {{ curl_get_http_status.stdout }} when attempting to GET from {{ swift_get_url }}"
when:
- curl_get_http_status is changed
- curl_get_http_status.stdout != "200" # deployment update
- 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"
when:
- curl_get_http_status is changed
- curl_get_http_status.stdout == "200"
- name: remove downloaded ceph-ansible fetch directory tarball from filesystem
file:
path: "/tmp/{{ old_ceph_ansible_tarball_name }}"
state: absent
when:
- curl_get_http_status is changed
- curl_get_http_status.stdout == "200"