From ac40b0f5ef2279564252b3434cd6689e63ce0513 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Fri, 13 Mar 2020 15:48:04 +0530 Subject: [PATCH] Add playbook for update deployment plan This adds the playbook and required modules. Depends-On: https://review.opendev.org/712896 Change-Id: I3090106fd24a82373ab308a1ba7f8bcd0eddecad --- .../modules/modules-tripleo_swift_tempurl.rst | 14 ++ .../modules/tripleo_swift_tempurl.py | 146 ++++++++++++++++++ .../playbooks/cli-update-deployment-plan.yaml | 101 ++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 doc/source/modules/modules-tripleo_swift_tempurl.rst create mode 100644 tripleo_ansible/ansible_plugins/modules/tripleo_swift_tempurl.py create mode 100644 tripleo_ansible/playbooks/cli-update-deployment-plan.yaml diff --git a/doc/source/modules/modules-tripleo_swift_tempurl.rst b/doc/source/modules/modules-tripleo_swift_tempurl.rst new file mode 100644 index 000000000..cb9472924 --- /dev/null +++ b/doc/source/modules/modules-tripleo_swift_tempurl.rst @@ -0,0 +1,14 @@ +============================== +Module - tripleo_swift_tempurl +============================== + + +This module provides for the following ansible plugin: + + * tripleo_swift_tempurl + + +.. ansibleautoplugin:: + :module: tripleo_ansible/ansible_plugins/modules/tripleo_swift_tempurl.py + :documentation: true + :examples: true diff --git a/tripleo_ansible/ansible_plugins/modules/tripleo_swift_tempurl.py b/tripleo_ansible/ansible_plugins/modules/tripleo_swift_tempurl.py new file mode 100644 index 000000000..8270d89e4 --- /dev/null +++ b/tripleo_ansible/ansible_plugins/modules/tripleo_swift_tempurl.py @@ -0,0 +1,146 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright (c) 2018 OpenStack Foundation +# 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. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import yaml + +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 + +# NOTE: This is still using the legacy clients. We've not +# changed to using the OpenStackSDK fully because +# tripleo-common expects the legacy clients. Once +# we've updated tripleo-common to use the SDK we +# should revise this. +import swiftclient +from tripleo_common.utils import swift as swift_utils + +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} + +DOCUMENTATION = ''' +--- +module: tripleo_swift_tempurl + +short_description: Get swift tempurl + +version_added: "2.8" + +description: + - "Get swift tempurl for object." + +options: + container: + description: + - Container name + type: str + default: overcloud-swift-rings + object: + description: + - Object name + type: str + defult: swift-rings.tar.gz + method: + description: + - An HTTP method to allow for this tempurl + type: str + default: GET + +author: + - Rabi Mishra (@ramishra) +''' + +EXAMPLES = ''' +- name: Get tempurl for swit backup + tripleo_swift_tempurl: + container: overcloud-swift-rings + object: swift-rings.tar.gz + method: GET + register: tempurl +''' + +RETURN = ''' +tempurl: + description: tempurl for object + returned: always + type: string + no_log: true +''' + + +def run_module(): + result = dict( + success=False, + error="", + changed=False, + tempurl="" + ) + + argument_spec = openstack_full_argument_spec( + **yaml.safe_load(DOCUMENTATION)['options'] + ) + + module = AnsibleModule( + argument_spec, + supports_check_mode=False, + **openstack_module_kwargs() + ) + + def get_object_client(session): + return swiftclient.Connection( + session=session, + retries=10, + starting_backoff=3, + max_backoff=120) + + try: + container = module.params.get('container') + obj = module.params.get('object') + method = module.params.get('method') + _, conn = openstack_cloud_from_module(module) + session = conn.session + + swift = get_object_client(session) + tempurl = swift_utils.get_temp_url(swift, container, obj, method) + result['success'] = True + result['changed'] = True + result['tempurl'] = tempurl + except Exception as err: + result['error'] = str(err) + result['msg'] = ("Error getting % tempurl for %/%s" % ( + method, container, obj, err)) + module.fail_json(**result) + + # in the event of a successful module execution, you will want to + # simple AnsibleModule.exit_json(), passing the key/value results + module.exit_json(**result) + + +def main(): + run_module() + + +if __name__ == '__main__': + main() diff --git a/tripleo_ansible/playbooks/cli-update-deployment-plan.yaml b/tripleo_ansible/playbooks/cli-update-deployment-plan.yaml new file mode 100644 index 000000000..2728b3675 --- /dev/null +++ b/tripleo_ansible/playbooks/cli-update-deployment-plan.yaml @@ -0,0 +1,101 @@ +--- +# 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: Update Deployment Plan + 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: + container: overcloud + source_url: null + generate_passwords: true + validate_stack: true + + handlers: + - name: Cleanup temp directory + file: + path: "{{ temp_dir.path }}" + state: absent + when: temp_dir is defined + + tasks: + - name: Clone repo and upload templates + block: + - name: Create temp directory + tempfile: + state: directory + suffix: "{{ '_' + container + '_import' }}" + register: temp_dir + notify: + - "Cleanup temp directory" + when: source_url is not none + + - name: Git clone remote url + git: + repo: "{{ source_url }}" + dest: "{{ temp_dir }}" + when: source_url is not none + + - name: Upload templates + tripleo_templates_upload: + container: "{{ container }}" + templates_dir: "{{ temp_dir.path }}" + when: source_url is not none + + when: source_url is not none + + - name: Generate passwords and update plan + tripleo_passwords_rotate: + container: "{{ container }}" + when: generate_passwords|bool + + - name: Prepare Container images and update plan + tripleo_image_params_prepare: + container: "{{ container }}" + with_roledata: false + + - name: Add root stack name + tripleo_plan_parameters_update: + container: "{{ container }}" + parameters: + RootStackName: "{{ container }}" + parameter_key: parameter_defaults + validate: false + + - name: Get backup tempurl for GET + tripleo_swift_tempurl: + container: "{{container + 'swift-rings' }}" + object: "swift-rings.tar.gz" + method: GET + register: backup_get_tempurl + + - name: Get backup tempurl for POST + tripleo_swift_tempurl: + container: "{{container + 'swift-rings' }}" + object: "swift-rings.tar.gz" + method: PUT + register: backup_put_tempurl + + - name: Update plan with backup tempurl parameters + tripleo_plan_parameters_update: + container: "{{ container }}" + parameters: + SwiftRingGetTempurl: "{{ backup_get_tempurl.tempurl }}" + SwiftRingPutTempurl: "{{ backup_put_tempurl.tempurl }}" + parameter_key: parameter_defaults + validate: false