tripleo-ansible/tripleo_ansible/playbooks/cli-config-download.yaml
James Slagle b6f1bfc408 Align tasks between config-download playbooks
cli-config-download.yaml and cli-config-download-export.yaml both
download the config from the stack. This commit aligns the tasks between
the 2 so that they both setup and download the config in the same way.

This allows a single playbook to be used by tripleoclient
(cli-config-download.yaml) as done in
Ia765c2c2ea548a1dcd20f592eda8741f40a1cf16

cli-config-download-export.yaml will be removed in a subsequent patch as
it will no longer be used by tripleoclient.

Change-Id: Ie47abe2d7c5d7891aceb88d9008d45d7922dea15
Signed-off-by: James Slagle <jslagle@redhat.com>
2021-08-05 21:51:13 -04:00

84 lines
2.9 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: Download config
connection: "{{ (tripleo_target_host is defined) | ternary('ssh', 'local') }}"
hosts: "{{ tripleo_target_host | default('localhost') }}"
remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}"
gather_facts: "{{ (tripleo_target_host is defined) | ternary(true, false) }}"
any_errors_fatal: true
vars:
plan: overcloud
ssh_network: ctlplane
ansible_ssh_user: tripleo-admin
ansible_ssh_private_key_file: /home/stack/.ssh/id_rsa
python_interpreter: null
config_type: null
preserve_config: true
tasks:
- name: Set output_dir
set_fact:
output_dir: "{{ lookup('env', 'HOME')~'/config-download'}}"
when: output_dir is not defined
- name: Set work_dir
set_fact:
work_dir: "{{ output_dir ~ '/' ~ plan }}"
- name: Clean work_dir
file:
path: "{{ work_dir }}"
state: absent
when: not preserve_config | bool
- name: Create config dir if does not exist
file:
path: "{{ work_dir }}"
state: directory
- name: Download config
tripleo_config_download:
plan: "{{ plan }}"
work_dir: "{{ work_dir }}"
download: true
config_type: "{{ config_type }}"
- name: Generate ansible inventory
tripleo_generate_ansible_inventory:
plan: "{{ plan }}"
work_dir: "{{ work_dir }}"
ssh_network: "{{ ssh_network }}"
ansible_ssh_user: "{{ ansible_ssh_user }}"
ansible_python_interpreter: "{{ python_interpreter }}"
ansible_ssh_private_key_file: "{{ ansible_ssh_private_key_file }}"
when: inventory_path is not defined or inventory_path != None
# TODO(mwhahaha): switch tripleo_generate_ansible_inventory to do this
# when we've nuked all the tripleo-ansible-inventory.yaml everywhere
- name: Copy inventory to AnsibleRunner location
block:
- name: Create inventory directory
ansible.builtin.file:
path: "{{ output_dir ~ '/' ~ plan }}/inventory"
state: directory
mode: 0700
- name: Copy generated inventory
ansible.builtin.copy:
src: "{{ work_dir }}/tripleo-ansible-inventory.yaml"
dest: "{{work_dir }}/inventory/tripleo"
remote_src: true