Add new playbook for container image prepare cli
This adds a new playbook for container image prepare command which will be used in tripleoclient and can also be used elsewhere. Change-Id: I8a1b9794723627bd458b5354155787bb1a2e26bc
This commit is contained in:
parent
3220e4e5e3
commit
e03f6bb595
@ -0,0 +1,14 @@
|
||||
=======================================
|
||||
Module - tripleo_build_heat_environment
|
||||
=======================================
|
||||
|
||||
|
||||
This module provides for the following ansible plugin:
|
||||
|
||||
* tripleo_build_heat_environment
|
||||
|
||||
|
||||
.. ansibleautoplugin::
|
||||
:module: tripleo_ansible/ansible_plugins/modules/tripleo_build_heat_environment.py
|
||||
:documentation: true
|
||||
:examples: true
|
@ -0,0 +1,91 @@
|
||||
# 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.
|
||||
import yaml
|
||||
|
||||
from ansible.module_utils import tripleo_common_utils as tc
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.openstack import openstack_full_argument_spec
|
||||
from ansible.module_utils.openstack import openstack_module_kwargs
|
||||
from ansible.module_utils.openstack import openstack_cloud_from_module
|
||||
|
||||
from heatclient.common import template_utils
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: tripleo_build_heat_environment
|
||||
short_description: Build heat stack environment
|
||||
author:
|
||||
- "Rabi Mishra (@ramishra)"
|
||||
version_added: "2.10"
|
||||
description:
|
||||
- Builds heat stack environment from environment files.
|
||||
options:
|
||||
container:
|
||||
description:
|
||||
- Name of plan / container
|
||||
type: str
|
||||
env_files:
|
||||
description:
|
||||
- List of environment files and directories
|
||||
type: list
|
||||
default: []
|
||||
requirements: ["tripleo-common"]
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Build heat environment
|
||||
tripleo_build_heat_environment:
|
||||
container: overcloud
|
||||
env_files: []
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
result = dict(
|
||||
success=False,
|
||||
changed=False,
|
||||
error=None,
|
||||
environment={}
|
||||
)
|
||||
module = AnsibleModule(
|
||||
openstack_full_argument_spec(
|
||||
**yaml.safe_load(DOCUMENTATION)['options']
|
||||
),
|
||||
**openstack_module_kwargs()
|
||||
)
|
||||
container = module.params.get('container')
|
||||
env_files = module.params.get('env_files')
|
||||
try:
|
||||
if container:
|
||||
_, conn = openstack_cloud_from_module(module)
|
||||
tripleo = tc.TripleOCommon(session=conn.session)
|
||||
heat = tripleo.get_orchestration_client()
|
||||
env = heat.environment(container)
|
||||
else:
|
||||
_, env = template_utils.process_multiple_environments_and_files(
|
||||
env_paths=env_files)
|
||||
result['environment'] = env
|
||||
result['changed'] = True
|
||||
result['success'] = True
|
||||
except Exception as ex:
|
||||
result['error'] = str(ex)
|
||||
result['msg'] = 'Error buiding environment: {}'.format(
|
||||
ex)
|
||||
module.fail_json(**result)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -116,6 +116,7 @@ def run_module():
|
||||
success=False,
|
||||
changed=False,
|
||||
error="",
|
||||
params={}
|
||||
)
|
||||
|
||||
argument_spec = openstack_full_argument_spec(
|
||||
@ -153,6 +154,7 @@ def run_module():
|
||||
|
||||
result['success'] = True
|
||||
result['changed'] = True
|
||||
result['params'] = {"parameter_defaults": params}
|
||||
except Exception as err:
|
||||
result['error'] = str(err)
|
||||
result['msg'] = ("Error running container image prepare: %s" % (err))
|
||||
|
72
tripleo_ansible/playbooks/cli-container-image-prepare.yaml
Normal file
72
tripleo_ansible/playbooks/cli-container-image-prepare.yaml
Normal file
@ -0,0 +1,72 @@
|
||||
---
|
||||
# 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: Container Image Prepare
|
||||
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:
|
||||
roles_file: /usr/share/openstack-tripleo-heat-templates/roles_data.yaml
|
||||
environment_files: []
|
||||
environment_directories: []
|
||||
cleanup: full
|
||||
dry_run: false
|
||||
debug: false
|
||||
log_file: container_image_prepare.log
|
||||
|
||||
tasks:
|
||||
- name: Fetch roles_data
|
||||
slurp:
|
||||
src: "{{ roles_file }}"
|
||||
register: roles_data
|
||||
- name: Set fact for log file
|
||||
set_fact:
|
||||
cip_log_file: "{{ lookup('env', 'HOME') ~ '/' ~ log_file }}"
|
||||
- name: Get all files in directories
|
||||
find:
|
||||
paths: "{{ environment_directories }}"
|
||||
patterns: '*.yaml'
|
||||
when: environment_directories
|
||||
register: out_env_files
|
||||
- name: Build environment_files
|
||||
set_fact:
|
||||
env_files: "{{ out_env_files.files | map(attribute='path') | list + environment_files }}"
|
||||
- name: Build heat stack environment
|
||||
tripleo_build_heat_environment:
|
||||
env_files: "{{ env_files }}"
|
||||
register: env_result
|
||||
- name: Prepare container images, check logs in {{ cip_log_file }}
|
||||
become: true
|
||||
tripleo_container_image_prepare:
|
||||
roles_data: "{{ roles_data['content'] | b64decode | from_yaml}}"
|
||||
environment: "{{ env_result.environment }}"
|
||||
cleanup: "{{ cleanup }}"
|
||||
dry_run: "{{ dry_run }}"
|
||||
log_file: "{{ cip_log_file }}"
|
||||
debug: "{{ debug }}"
|
||||
register: prepare_result
|
||||
- name: Write output to file to {{ output_env_file }}
|
||||
copy:
|
||||
content: "{{ prepare_result.params | to_nice_yaml }}"
|
||||
backup: true
|
||||
dest: "{{ output_env_file }}"
|
||||
when: output_env_file is defined
|
||||
- name: Write output to console
|
||||
debug:
|
||||
msg: "{{ prepare_result.params | to_nice_yaml }}"
|
||||
when: output_env_file is not defined
|
Loading…
Reference in New Issue
Block a user