tripleo-ansible/tripleo_ansible/playbooks/cli-overcloud-node-unprovis...

66 lines
2.2 KiB
YAML

---
# Copyright 2020 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: Overcloud Node Unprovision
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:
prompt: true
all: false
pre_tasks:
- fail:
msg: stack_name is a required input
when:
- stack_name is undefined
- fail:
msg: baremetal_deployment is a required input
when:
- baremetal_deployment is undefined
- fail:
msg: unprovision_confirm is required when prompt is true
when:
- prompt
- unprovision_confirm is undefined
tasks:
- name: Expand roles
tripleo_baremetal_expand_roles:
baremetal_deployment: "{{ baremetal_deployment }}"
stack_name: "{{ stack_name }}"
state: "{{ all|bool and 'all' or 'absent' }}"
register: baremetal_instances
- name: Find existing instances
tripleo_baremetal_check_existing:
instances: "{{ baremetal_instances.instances }}"
register: baremetal_existing
- name: Write unprovision confirmation
copy:
dest: "{{ unprovision_confirm }}"
content: "{{ baremetal_existing.instances | to_json }}"
when: prompt|bool and unprovision_confirm is defined
- name: Unprovision instances
metalsmith_instances:
instances: "{{ baremetal_existing.instances }}"
state: absent
when: not prompt|bool