Add overcloud credentials

Adds tripleo_overcloud_credentials to run the command to output plan rc
files.

Change-Id: I6cccb13a81ce43d20be0bdc3061726c474431cea
This commit is contained in:
Alex Schultz
2020-03-24 11:12:07 -06:00
parent 2cdf88dad5
commit 4de93a0ca7
10 changed files with 251 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
tripleo_overcloud_credentials
=============================
A role to run the credentials action to output the cloud rc files.
Requirements
------------
None.
Role Variables
--------------
* `tripleo_overcloud_credentials_debug`: (Boolean) Flag to print out the delete command. Default: False
* `tripleo_overcloud_credentials_directory`: (String) The directory to create the rc files in. Defaults to current working directory which will be `tripleo_overcloud_credentials_home_dir`.
* `tripleo_overcloud_credentials_home_dir`: (String) Home directory to where the command is run from. Default: "{{ ansible_env.HOME }}"
* `tripleo_overcloud_credentials_log_combine`: (Boolean) Flag to enable captching stderr with stdout. Default: true
* `tripleo_overcloud_credentials_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_credentials_log`: (String) Path to a log file for the command output. Default: "{{ tripleo_overcloud_credentials_home_dir }}/overcloud_credentials.log"
* `tripleo_overcloud_credentials_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_credentials_rc_file`.
* `tripleo_overcloud_credentials_plan`: (String) REQUIRED. The name of the plan you wan to create rc files for.
* `tripleo_overcloud_credentials_poll`: (Integer) Number of seconds to wait between each checks to see if the command has completed. Default: 10
* `tripleo_overcloud_credentials_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_credentials_timeout`: (Integer) Number in seconds to wait for the ansible execution of the command to finish. Default: 3600
Output Variables
----------------
* `tripleo_overcloud_credentials_output`: (String) The command standard output.
* `tripleo_overcloud_credentials_result`: Ansible shell execution results
Dependencies
------------
None.
Example Playbook
----------------
Example overcloud crednetials playbook
```yaml
- hosts: undercloud
gather_facts: true
tasks:
- name: Run overcloud credentials
import_role:
name: tripleo_overcloud_credentials
var:
tripleo_overcloud_credentials_debug: true
```
License
-------
Apache-2.0

View File

@@ -0,0 +1,14 @@
---
# defaults file for tripleo_overcloud_credentials
openstack_bin: openstack
tripleo_overcloud_credentials_debug: false
tripleo_overcloud_credentials_directory:
tripleo_overcloud_credentials_home_dir: "{{ ansible_env.HOME }}"
tripleo_overcloud_credentials_log: "{{ tripleo_overcloud_credentials_home_dir }}/overcloud_credentials.log"
tripleo_overcloud_credentials_log_combine: true
tripleo_overcloud_credentials_log_output: true
tripleo_overcloud_credentials_os_cloud: "{{ tripleo_os_cloud | default('') }}"
tripleo_overcloud_credentials_plan:
tripleo_overcloud_credentials_poll: 10
tripleo_overcloud_credentials_rc_file: "{{ tripleo_rc_file | default(ansible_env.HOME ~ '/stackrc') }}"
tripleo_overcloud_credentials_timeout: 3600

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_credentials
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,43 @@
---
- name: Converge
hosts: all
collections:
- tripleo.operator
vars:
openstack_bin: echo
tripleo_os_cloud: undercloud
tripleo_overcloud_credentials_log_output: false
tripleo_overcloud_credentials_poll: 1
tripleo_overcloud_credentials_debug: true
tasks:
- name: "Include tripleo_overcloud_credentials"
include_role:
name: "tripleo_overcloud_credentials"
- name: Check role
assert:
that:
- tripleo_overcloud_credentials_output == "overcloud credentials"
- name: Assert "tripleo_overcloud_credentials_plan"
include_role:
name: "tripleo_overcloud_credentials"
vars:
tripleo_overcloud_credentials_plan: foo
- name: Verify tripleo_overcloud_credentials_plan
assert:
that:
- tripleo_overcloud_credentials_output == "overcloud credentials foo"
- name: Assert "tripleo_overcloud_credentials_directory"
include_role:
name: "tripleo_overcloud_credentials"
vars:
tripleo_overcloud_credentials_directory: /foo
- name: Verify tripleo_overcloud_credentials_plan
assert:
that:
- tripleo_overcloud_credentials_output == "overcloud credentials --directory /foo"

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,47 @@
---
# tasks file for tripleo_overcloud_credentials
- name: CHANGEME
set_fact:
_creds_cmd: >-
{{ tripleo_overcloud_credentials_os_cloud | ternary('', "source " ~ tripleo_overcloud_credentials_rc_file ~ "; ") }}
{{ openstack_bin }} overcloud credentials
{{ tripleo_overcloud_credentials_directory | ternary('--directory $CREDENTIALS_DIR', '') }}
{{ tripleo_overcloud_credentials_plan }}
{{ tripleo_overcloud_credentials_log_output | ternary((">" ~ tripleo_overcloud_credentials_log), '') }}
{{ tripleo_overcloud_credentials_log_combine | ternary("2>&1", '') }}
_creds_env:
CREDENTIALS_DIR: "{{ tripleo_overcloud_credentials_directory }}"
OS_CLOUD: "{{ tripleo_overcloud_credentials_os_cloud }}"
- name: Preserve existing log file if exists
timestamp_file:
path: "{{ tripleo_overcloud_credentials_log }}"
when: tripleo_overcloud_credentials_log_output|bool
- name: Show debug information
when: tripleo_overcloud_credentials_debug|bool
block:
- name: Show the command
debug:
var: _creds_cmd
- name: Show the environment
debug:
var: _creds_env
- name: CHANGEME
shell: "{{ _creds_cmd }}" # noqa 305
environment: "{{ _creds_env }}"
args:
executable: /bin/bash
chdir: "{{ tripleo_overcloud_credentials_home_dir }}"
warn: false
register: tripleo_overcloud_credentials_result
async: "{{ tripleo_overcloud_credentials_timeout }}"
poll: "{{ tripleo_overcloud_credentials_poll }}"
changed_when: false
when: not ansible_check_mode|bool
- name: Set output fact
set_fact:
tripleo_overcloud_credentials_output: "{{ tripleo_overcloud_credentials_result.stdout }}"

View File

@@ -0,0 +1 @@
localhost

View File

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

View File

@@ -19,6 +19,7 @@
- tripleo-operator-molecule-tripleo_overcloud_container_image_prepare
- tripleo-operator-molecule-tripleo_overcloud_container_image_tag_discover
- tripleo-operator-molecule-tripleo_overcloud_container_image_upload
- tripleo-operator-molecule-tripleo_overcloud_credentials
- tripleo-operator-molecule-tripleo_overcloud_deploy
- tripleo-operator-molecule-tripleo_overcloud_export
- tripleo-operator-molecule-tripleo_overcloud_external_update_run
@@ -70,6 +71,7 @@
- tripleo-operator-molecule-tripleo_overcloud_container_image_prepare
- tripleo-operator-molecule-tripleo_overcloud_container_image_tag_discover
- tripleo-operator-molecule-tripleo_overcloud_container_image_upload
- tripleo-operator-molecule-tripleo_overcloud_credentials
- tripleo-operator-molecule-tripleo_overcloud_deploy
- tripleo-operator-molecule-tripleo_overcloud_export
- tripleo-operator-molecule-tripleo_overcloud_external_update_run
@@ -321,6 +323,20 @@
vars:
tox_extra_args: tripleo_overcloud_container_image_upload
- job:
files:
- ^roles/tripleo_overcloud_credentials/.*
- ^bindep.txt
- ^galaxy.yml
- ^requirements.txt
- ^setup.cfg
- ^test-requirements.txt
- ^tox.ini
name: tripleo-operator-molecule-tripleo_overcloud_credentials
parent: tripleo-operator-molecule-base
vars:
tox_extra_args: tripleo_overcloud_credentials
- job:
files:
- ^roles/tripleo_overcloud_deploy/.*