3d2d6393ea
Improve error handling if deployer sets the variable for local_ceph_ansible_fetch_directory_backup to a directory which ansible cannot write to. Instead of failing the deployment with a message that the object has no attribute stat, fail with a message explaining what happened and how to fix. Change-Id: Ib13f367b23126df35902a260ab25f99adc898245
90 lines
4.1 KiB
YAML
90 lines
4.1 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: fail if ansible does not have necessary permissions on local_backup_directory
|
|
fail:
|
|
msg: >-
|
|
The user running Ansible needs to be able to read and write to
|
|
the '{{ local_ceph_ansible_fetch_directory_backup }}' directory.
|
|
Please set the LocalCephAnsibleFetchDirectoryBackup Heat parameter or
|
|
the local_ceph_ansible_fetch_directory_backup Ansible parameter to a
|
|
directory the user '{{ lookup('env','USER') }}' can read and write to.
|
|
when:
|
|
- (local_backup_directory.msg is defined and
|
|
local_backup_directory.msg == "Permission denied")
|
|
or
|
|
(local_backup_directory.stat is defined and
|
|
local_backup_directory.stat.exists and
|
|
not local_backup_directory.stat.writeable)
|
|
- 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:
|
|
- local_backup_directory.stat is defined
|
|
- 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 is defined
|
|
- 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"
|