Add overcloud node unprovision

Adds tripleo_overcloud_node_unprovision to perform baremetal node
unprovisioning with Ironic.

Change-Id: I76ffe4a6235ae72d53c7c96d8c64756c45ffd434
This commit is contained in:
Alex Schultz 2020-03-17 10:58:05 -06:00
parent eaf66208cb
commit 4452f67b11
10 changed files with 273 additions and 0 deletions

View File

@ -0,0 +1,60 @@
tripleo_overcloud_node_unprovision
=========
A role to perform unprovisioning of nodes using Ironic.
Requirements
------------
None.
Role Variables
--------------
* `tripleo_overcloud_node_unprovision_all`: (Boolean) Unprovision every instance in the deployment. Defaults: false
* `tripleo_overcloud_node_unprovision_debug`: (Boolean) Flag to print out the delete command. Default: False
* `tripleo_overcloud_node_unprovision_deployment_file`: (String) REQUIRED. Configuration file describing the baremetal deployment.
* `tripleo_overcloud_node_unprovision_home_dir`: (String) Home directory to where the command is run from. Default: "{{ ansible_env.HOME }}"
* `tripleo_overcloud_node_unprovision_log_combine`: (Boolean) Flag to enable captching stderr with stdout. Default: true
* `tripleo_overcloud_node_unprovision_log_output`: (Boolean) Flag to enable logging to a file. Since the output of this command can be large, it is not recommended to disable this. Default: true
* `tripleo_overcloud_node_unprovision_log`: (String) Path to a log file for the command output. Default: "{{ tripleo_overcloud_node_unprovision_home_dir }}/overcloud_node_unprovision.log"
* `tripleo_overcloud_node_unprovision_os_cloud`: (String) (String) OS_CLOUD value to use when running the command. If `tripleo_os_cloud` is defined, it will be the default. Otherwise the default is ''. This variable takes precedence over `tripleo_overcloud_node_unprovision_rc_file`.
* `tripleo_overcloud_node_unprovision_poll`: (Integer) Number of seconds to wait between each checks to see if the command has completed. Default: 10
* `tripleo_overcloud_node_unprovision_rc_file`: (String) (String) Path to the credential file to use. If `tripleo_rc_file` is defined, it will be the default. Default: "{{ ansible_env.HOME }}/stackrc"
* `tripleo_overcloud_node_unprovision_stack`: (String) Name or ID of the heat stack
* `tripleo_overcloud_node_unprovision_timeout`: (Integer) Number in seconds to wait for the ansible execution of the command to finish. Default: 3600
* `tripleo_overcloud_node_unprovision_yes`: (Boolean) Skip yes/no prompt. Defualt: true
Output Variables
----------------
* `tripleo_overcloud_node_unprovision_output`: (String) The command standard output.
* `tripleo_overcloud_node_unprovision_result`: Ansible shell execution results
Dependencies
------------
None.
Example Playbook
----------------
Example unprovision
```yaml
- hosts: undercloud
gather_facts: true
tasks:
- name: Run overcloud node unprovision
import_role:
name: tripleo_overcloud_node_unprovision
var:
tripleo_overcloud_node_unprovision_debug: true
tripleo_overcloud_node_unprovision_deployment_file: /home/stack/deployment.yaml
tripleo_overcloud_node_unprovision_all: true
```
License
-------
Apache-2.0

View File

@ -0,0 +1,16 @@
---
# defaults file for tripleo_overcloud_node_unprovision
openstack_bin: openstack
tripleo_overcloud_node_unprovision_all: false
tripleo_overcloud_node_unprovision_debug: false
tripleo_overcloud_node_unprovision_deployment_file:
tripleo_overcloud_node_unprovision_home_dir: "{{ ansible_env.HOME }}"
tripleo_overcloud_node_unprovision_log: "{{ tripleo_overcloud_node_unprovision_home_dir }}/CHANGEME.log"
tripleo_overcloud_node_unprovision_log_combine: true
tripleo_overcloud_node_unprovision_log_output: true
tripleo_overcloud_node_unprovision_os_cloud: "{{ tripleo_os_cloud | default('') }}"
tripleo_overcloud_node_unprovision_poll: 10
tripleo_overcloud_node_unprovision_rc_file: "{{ tripleo_rc_file | default(ansible_env.HOME ~ '/stackrc') }}"
tripleo_overcloud_node_unprovision_stack:
tripleo_overcloud_node_unprovision_timeout: 3600
tripleo_overcloud_node_unprovision_yes: true

View File

@ -0,0 +1,42 @@
---
# 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.
galaxy_info:
author: OpenStack
description: TripleO Operator Role -- tripleo_overcloud_node_unprovision
company: Red Hat
license: Apache-2.0
min_ansible_version: 2.8
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: CentOS
versions:
- 7
- 8
galaxy_tags:
- tripleo
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies: []

View File

@ -0,0 +1,57 @@
---
- name: Converge
hosts: all
collections:
- tripleo.operator
vars:
openstack_bin: echo
tripleo_os_cloud: undercloud
tripleo_overcloud_node_unprovision_log_output: false
tripleo_overcloud_node_unprovision_poll: 1
tripleo_overcloud_node_unprovision_debug: true
tasks:
- name: "Include tripleo_overcloud_node_unprovision"
include_role:
name: "tripleo_overcloud_node_unprovision"
- name: Check role
assert:
that:
- tripleo_overcloud_node_unprovision_output == "overcloud node unprovision --yes"
- name: Assert "tripleo_overcloud_node_unprovision_stack"
include_role:
name: "tripleo_overcloud_node_unprovision"
vars:
tripleo_overcloud_node_unprovision_stack: foo
- name: Validate tripleo_overcloud_node_unprovision_stack
assert:
that:
- tripleo_overcloud_node_unprovision_output ==
"overcloud node unprovision --stack foo --yes"
- name: Assert "tripleo_overcloud_node_unprovision_all"
include_role:
name: "tripleo_overcloud_node_unprovision"
vars:
tripleo_overcloud_node_unprovision_all: true
- name: Validate tripleo_overcloud_node_unprovision_all
assert:
that:
- tripleo_overcloud_node_unprovision_output ==
"overcloud node unprovision --all --yes"
- name: Assert "tripleo_overcloud_node_unprovision_deployment_file"
include_role:
name: "tripleo_overcloud_node_unprovision"
vars:
tripleo_overcloud_node_unprovision_deployment_file: foo.yaml
- name: Validate tripleo_overcloud_node_unprovision_deployment_file
assert:
that:
- tripleo_overcloud_node_unprovision_output ==
"overcloud node unprovision --yes foo.yaml"

View File

@ -0,0 +1,19 @@
---
driver:
name: delegated
options:
managed: false
ansible_connection_options:
ansible_connection: local
log: true
platforms:
- name: instance
provisioner:
name: ansible
scenario:
name: default
test_sequence:
- prepare
- syntax
- converge
- verify

View File

@ -0,0 +1,8 @@
---
- name: Prepare
hosts: all
tasks:
- name: Include molecule prep
include_role:
name: test_molecule_prep

View File

@ -0,0 +1,49 @@
---
# tasks file for tripleo_overcloud_node_unprovision
- name: Set overcloud node unprovision facts
set_fact:
_unprovision_cmd: >-
{{ tripleo_overcloud_node_unprovision_os_cloud | ternary('', "source " ~ tripleo_overcloud_node_unprovision_rc_file ~ "; ") }}
{{ openstack_bin }} overcloud node unprovision
{{ tripleo_overcloud_node_unprovision_stack | ternary('--stack $UNPROVISION_STACK', '') }}
{{ tripleo_overcloud_node_unprovision_all | ternary('--all', '') }}
{{ tripleo_overcloud_node_unprovision_yes | ternary('--yes', '') }}
{{ tripleo_overcloud_node_unprovision_deployment_file }}
{{ tripleo_overcloud_node_unprovision_log_output | ternary((">" ~ tripleo_overcloud_node_unprovision_log), '') }}
{{ tripleo_overcloud_node_unprovision_log_combine | ternary("2>&1", '') }}
_unprovision_env:
OS_CLOUD: "{{ tripleo_overcloud_node_unprovision_os_cloud }}"
UNPROVISION_STACK: "{{ tripleo_overcloud_node_unprovision_stack | quote }}"
- name: Preserve existing log file if exists
timestamp_file:
path: "{{ tripleo_overcloud_node_unprovision_log }}"
when: tripleo_overcloud_node_unprovision_log_output|bool
- name: Show debug information
when: tripleo_overcloud_node_unprovision_debug|bool
block:
- name: Show the command
debug:
var: _unprovision_cmd
- name: Show the environment
debug:
var: _unprovision_env
- name: overcloud node unprovision
shell: "{{ _unprovision_cmd }}" # noqa 305
environment: "{{ _unprovision_env }}"
args:
executable: /bin/bash
chdir: "{{ tripleo_overcloud_node_unprovision_home_dir }}"
warn: false
register: tripleo_overcloud_node_unprovision_result
async: "{{ tripleo_overcloud_node_unprovision_timeout }}"
poll: "{{ tripleo_overcloud_node_unprovision_poll }}"
changed_when: false
when: not ansible_check_mode|bool
- name: Set output fact
set_fact:
tripleo_overcloud_node_unprovision_output: "{{ tripleo_overcloud_node_unprovision_result.stdout }}"

View File

@ -0,0 +1 @@
localhost

View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- tripleo_overcloud_node_unprovision

View File

@ -28,6 +28,7 @@
- tripleo-operator-molecule-tripleo_overcloud_node_import
- tripleo-operator-molecule-tripleo_overcloud_node_provide
- tripleo-operator-molecule-tripleo_overcloud_node_provision
- tripleo-operator-molecule-tripleo_overcloud_node_unprovision
- tripleo-operator-molecule-tripleo_overcloud_update_converge
- tripleo-operator-molecule-tripleo_overcloud_update_prepare
- tripleo-operator-molecule-tripleo_overcloud_update_run
@ -67,6 +68,7 @@
- tripleo-operator-molecule-tripleo_overcloud_node_import
- tripleo-operator-molecule-tripleo_overcloud_node_provide
- tripleo-operator-molecule-tripleo_overcloud_node_provision
- tripleo-operator-molecule-tripleo_overcloud_node_unprovision
- tripleo-operator-molecule-tripleo_overcloud_update_converge
- tripleo-operator-molecule-tripleo_overcloud_update_prepare
- tripleo-operator-molecule-tripleo_overcloud_update_run
@ -349,6 +351,20 @@
vars:
tox_extra_args: tripleo_overcloud_node_provision
- job:
files:
- ^roles/tripleo_overcloud_node_unprovision/.*
- ^bindep.txt
- ^galaxy.yml
- ^requirements.txt
- ^setup.cfg
- ^test-requirements.txt
- ^tox.ini
name: tripleo-operator-molecule-tripleo_overcloud_node_unprovision
parent: tripleo-operator-molecule-base
vars:
tox_extra_args: tripleo_overcloud_node_unprovision
- job:
files:
- ^roles/tripleo_overcloud_node_configure/.*