From bf90885e135499d44f7805e198272331037f660a Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Wed, 15 Jan 2020 15:00:16 -0700 Subject: [PATCH] Add container image prepare role Adds tripleo_container_image_prepare role to execute the tripleo container image prepare process. Change-Id: Iec1c2a3afa9c6e2ef0011036749f294a1d9b9508 --- .../tripleo_container_image_prepare/README.md | 52 +++++++++++++++++++ .../defaults/main.yml | 11 ++++ .../meta/main.yml | 42 +++++++++++++++ .../tasks/main.yml | 25 +++++++++ .../tests/inventory | 2 + .../tests/test.yml | 5 ++ 6 files changed, 137 insertions(+) create mode 100644 roles/tripleo_container_image_prepare/README.md create mode 100644 roles/tripleo_container_image_prepare/defaults/main.yml create mode 100644 roles/tripleo_container_image_prepare/meta/main.yml create mode 100644 roles/tripleo_container_image_prepare/tasks/main.yml create mode 100644 roles/tripleo_container_image_prepare/tests/inventory create mode 100644 roles/tripleo_container_image_prepare/tests/test.yml diff --git a/roles/tripleo_container_image_prepare/README.md b/roles/tripleo_container_image_prepare/README.md new file mode 100644 index 0000000..d75be62 --- /dev/null +++ b/roles/tripleo_container_image_prepare/README.md @@ -0,0 +1,52 @@ +tripleo_container_image_prepare +=============================== + +A role to perform the container image prepare action. + +Requirements +------------ + +None. + +Role Variables +-------------- + +* `tripleo_container_image_prepare_become`: (Boolean) Run the command as root. This needs to be true when uploading to the local undercloud registry. Default: true +* `tripleo_container_image_prepare_cleanup`: (String) Cleanup behavior for local images left after upload. Can be one of full, partial, or none. Default is not set. +* `tripleo_container_image_prepare_debug`: (Boolean) Flag to print out the prepare command. Default: False +* `tripleo_container_image_prepare_dry_run`: (Boolean) Perform a dry run upload which will not perform any push, pull or modify operations. The environment file will still be populaged. Default: false +* `tripleo_container_image_prepare_environment_files`: (List) List of environment files. Default: [] +* `tripleo_container_image_prepare_environment_directory`: (List) Directories containing environment files. Should not be used if `tripleo_container_image_prepare_environment_files` is defined. Default: [] +* `tripleo_container_image_prepare_output_env_file`: (String) File to write heat environment file which specifies all image parameters. Default is not set. +* `tripleo_container_image_prepare_output_roles_file`: (String) Roles file path on the remote system. Default is not set. +* `tripleo_container_image_prepare_timeout`: (Number) Amount of time to wait for the command to conplete. Default: 1800 + +Output Variables +---------------- + +* `tripleo_container_image_prepare_result`: Ansible shell execution results + +Dependencies +------------ + +None. + +Example Playbook +---------------- + +Example container prepare execution playbook + + - hosts: undercloud + gather_facts: true + tasks: + - name: Run container prepare + import_role: + name: tripleo_container_image_prepare + vars: + tripleo_container_image_prepare_files: + - /home/stack/container-image-prepare.yaml + +License +------- + +Apache-2.0 diff --git a/roles/tripleo_container_image_prepare/defaults/main.yml b/roles/tripleo_container_image_prepare/defaults/main.yml new file mode 100644 index 0000000..e715423 --- /dev/null +++ b/roles/tripleo_container_image_prepare/defaults/main.yml @@ -0,0 +1,11 @@ +--- +# defaults file for tripleo_container_image_prepare +tripleo_container_image_prepare_become: true +tripleo_container_image_prepare_cleanup: +tripleo_container_image_prepare_debug: false +tripleo_container_image_prepare_dry_run: false +tripleo_container_image_prepare_environemnt_files: [] +tripleo_container_image_prepare_environment_directory: [] +tripleo_container_image_prepare_output_env_file: +tripleo_container_image_prepare_roles_file: +tripleo_container_image_prepare_timeout: 1800 diff --git a/roles/tripleo_container_image_prepare/meta/main.yml b/roles/tripleo_container_image_prepare/meta/main.yml new file mode 100644 index 0000000..1124bb0 --- /dev/null +++ b/roles/tripleo_container_image_prepare/meta/main.yml @@ -0,0 +1,42 @@ +--- +# 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. + + +galaxy_info: + author: OpenStack + description: TripleO Operator Role -- tripleo_container_image_prepare + 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: [] diff --git a/roles/tripleo_container_image_prepare/tasks/main.yml b/roles/tripleo_container_image_prepare/tasks/main.yml new file mode 100644 index 0000000..1eca933 --- /dev/null +++ b/roles/tripleo_container_image_prepare/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# tasks file for tripleo_container_image_prepare +- name: Setup container image prepare facts + set_fact: + _prepare_cmd: >- + openstack tripleo container image prepare + {{ tripleo.operator.shell_arg_list(tripleo_container_image_prepare_environment_files, '--environment-file') }} + {{ tripleo.operator.shell_arg_list(tripleo_container_image_prepare_environment_directory, '--environment-directory') }} + {{ tripleo_container_image_prepare_roles_file | ternary('--roles-file ' ~ tripleo_container_image_prepare_roles_file, '') }} + {{ tripleo_container_image_prepare_output_env_file | ternary('--output-env-file ' ~ tripleo_container_image_prepare_output_env_file, '') }} + {{ tripleo_container_image_prepare_dry_run | ternary('--dry-run', '') }} + {{ tripleo_container_image_prepare_cleanup | ternary('--cleanup ' ~ tripleo_container_image_prepare_cleanup, '') }} + +- name: Show the container image prepare command + debug: + var: _prepare_cmd + when: tripleo_container_image_prepare_debug|bool + +- name: Container image prepare + shell: "{{ _prepare_cmd }}" # noqa 305 + async: "{{ tripleo_container_image_prepare_timeout }}" + poll: 1 + become: "{{ tripleo_container_image_prepare_become }}" + register: tripleo_container_image_prepare_result + changed_when: true diff --git a/roles/tripleo_container_image_prepare/tests/inventory b/roles/tripleo_container_image_prepare/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/tripleo_container_image_prepare/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/tripleo_container_image_prepare/tests/test.yml b/roles/tripleo_container_image_prepare/tests/test.yml new file mode 100644 index 0000000..db7eec8 --- /dev/null +++ b/roles/tripleo_container_image_prepare/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - tripleo_container_image_prepare