tripleo-ansible/tripleo_ansible/roles/tripleo_ceph_run_ansible/tasks/main.yml

149 lines
6.3 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: set ceph-ansible playbook list
set_fact:
ceph_ansible_playbooks: >
{%- if ceph_ansible_playbooks_param != ['default'] -%}
{{ ceph_ansible_playbooks_param }}
{%- else -%}
{{ ceph_ansible_playbooks_default|default(['/usr/share/ceph-ansible/site-container.yml.sample']) }}
{%- endif -%}
- name: set ceph-ansible command list
set_fact:
ceph_ansible_command_list:
- ANSIBLE_ACTION_PLUGINS=/usr/share/ceph-ansible/plugins/actions/
- ANSIBLE_CALLBACK_PLUGINS=/usr/share/ceph-ansible/plugins/callback/
- ANSIBLE_FILTER_PLUGINS=/usr/share/ceph-ansible/plugins/filter/
- ANSIBLE_ROLES_PATH=/usr/share/ceph-ansible/roles/
- ANSIBLE_LOG_PATH="{{ playbook_dir }}/ceph-ansible/ceph_ansible_command.log"
- ANSIBLE_LIBRARY=/usr/share/ceph-ansible/library/
- ANSIBLE_CONFIG=/usr/share/ceph-ansible/ansible.cfg
- ANSIBLE_REMOTE_TEMP=/tmp/ceph_ansible_tmp
- ANSIBLE_FORKS=25
- ANSIBLE_GATHER_TIMEOUT=60
- "{{ calling_ansible_environment_variables|join(' ') }}"
- "{{ ceph_ansible_environment_variables|join(' ') }}"
- ansible-playbook
- '{% if ceph_ansible_private_key_file is defined %}--private-key {{ ceph_ansible_private_key_file }}{% endif %}'
- '{% if ansible_python_interpreter is defined %}-e ansible_python_interpreter={{ ansible_python_interpreter }}{% endif %}'
- '-{%- for number in range(0, ceph_ansible_playbook_verbosity) -%}v{% endfor %}'
- '{% if ceph_ansible_skip_tags is defined and ceph_ansible_skip_tags|length > 0%}--skip-tags {{ ceph_ansible_skip_tags }}{% endif %}'
- '--extra-vars'
- '@{{ playbook_dir }}/ceph-ansible/extra_vars.yml'
- '{% if ceph_ansible_limit is defined and ceph_ansible_limit|length > 0 %}--limit {{ ceph_ansible_limit }}{% endif %}'
- name: try to find ANSIBLE_LOG_PATH in ceph_ansible_environment_variables
set_fact:
calling_ansible_log_path: "{{ item | regex_replace('ANSIBLE_LOG_PATH=', '') }}"
when: item is match("ANSIBLE_LOG_PATH.*")
loop: "{{ ceph_ansible_environment_variables }}"
- name: do we need to keep looking for the ANSIBLE_LOG_PATH?
when: calling_ansible_log_path is undefined
block:
- name: try to find ANSIBLE_LOG_PATH in calling_ansible_environment_variables
set_fact:
calling_ansible_log_path: "{{ item | regex_replace('ANSIBLE_LOG_PATH=', '') }}"
when: item is match("ANSIBLE_LOG_PATH.*")
loop: "{{ calling_ansible_environment_variables }}"
- name: Set ANSIBLE_LOG_PATH to default
when: calling_ansible_log_path is undefined
set_fact:
calling_ansible_log_path: "{{ playbook_dir }}/ceph-ansible/ceph_ansible_command.log"
- name: save ceph-ansible playbook command(s) to shell script
copy:
dest: "{{ playbook_dir }}/ceph-ansible/ceph_ansible_command.sh"
mode: '0755'
content: |
#!/usr/bin/env bash
set -e
echo "Running $0" >> {{ calling_ansible_log_path }}
{% set inv = "-i "+ playbook_dir +"/ceph-ansible/inventory.yml" %}
{% for playbook in ceph_ansible_playbooks %}
{{ ceph_ansible_command_list|join(' ') }} {{ inv }} {{ playbook }} 2>&1
{% endfor %}
- when:
- ceph_external_multi_config is defined
- (ceph_external_multi_config|length) > 0
block:
- name: set default facts for ceph_scripts list
set_fact:
ceph_prefix: "{{ playbook_dir + '/ceph-ansible/external_' }}"
ceph_suffix: '_ceph_ansible_command.sh'
ceph_default: "{{ [playbook_dir + '/ceph-ansible/ceph_ansible_command.sh'] }}"
- name: save external ceph-ansible playbook command(s) to shell script(s)
copy:
dest: "{{ ceph_prefix + item + ceph_suffix }}"
mode: '0755'
content: |
#!/usr/bin/env bash
set -e
echo "Running $0" >> {{ calling_ansible_log_path }}
{% set inv = "-i " + ceph_prefix + "inventory.ini" %}
{% set extra = "-e @" + ceph_prefix + item + "_extra_vars.yml" %}
{% for playbook in ceph_ansible_playbooks %}
{{ ceph_ansible_command_list|join(' ') }} {{ inv }} {{ extra }} {{ playbook }} 2>&1
{% endfor %}
loop: "{{ ceph_external_multi_config | map(attribute='cluster') | list }}"
- name: add external ceph-ansible shell script(s) to list of ceph_scripts
set_fact:
ceph_scripts: "{{ ceph_scripts|default(ceph_default) + [ceph_prefix + item + ceph_suffix] }}"
loop: "{{ ceph_external_multi_config | map(attribute='cluster') | list }}"
- name: "Notify user about upcoming ceph-ansible execution(s)"
debug:
msg: "Running {{ ceph_scripts|default(['ceph_ansible_command.sh'])|length }} ceph-ansible playbook(s) (immediate log at {{ calling_ansible_log_path }})"
- name: run ceph-ansible
# Needs become to be able to read the ssh private key
become: true
shell: "{{ item }}"
# We want the output chunked into bits to prevent
# overflowing Zaqar message size
no_log: "{{ not (tripleo_ceph_run_ansible_debug | bool) }}"
failed_when: false
register: outputs
tags: run_ceph_ansible
when: outputs.rc is undefined or outputs.rc == 0
loop: "{{ ceph_scripts | default([playbook_dir + '/ceph-ansible/ceph_ansible_command.sh']) }}"
- name: search output of ceph-ansible run(s) non-zero return codes
set_fact:
ceph_ansible_std_out_err: "{{ item.stdout_lines | default([]) | union(item.stderr_lines | default([])) }}"
no_log: "{{ tripleo_ceph_run_ansible_hide_sensitive_logs | bool }}"
when:
- item.rc is defined
- item.rc != 0
loop: "{{ outputs.results }}"
tags:
- run_ceph_ansible
- name: print ceph-ansible output in case of failure
debug:
var: ceph_ansible_std_out_err
when:
- ceph_ansible_std_out_err is defined
failed_when:
- ceph_ansible_std_out_err is defined
tags:
- run_ceph_ansible