Add deploy plan playbook
Change-Id: I42a65e379981fe7d7879ae5061eafe32845887b7 Depends-On: https://review.opendev.org/713580
This commit is contained in:
parent
ac40b0f5ef
commit
91a2b34b13
14
doc/source/modules/modules-tripleo_plan_deploy.rst
Normal file
14
doc/source/modules/modules-tripleo_plan_deploy.rst
Normal file
@ -0,0 +1,14 @@
|
||||
============================
|
||||
Module - tripleo_plan_deploy
|
||||
============================
|
||||
|
||||
|
||||
This module provides for the following ansible plugin:
|
||||
|
||||
* tripleo_plan_deploy
|
||||
|
||||
|
||||
.. ansibleautoplugin::
|
||||
:module: tripleo_ansible/ansible_plugins/modules/tripleo_plan_deploy.py
|
||||
:documentation: true
|
||||
:examples: true
|
146
tripleo_ansible/ansible_plugins/modules/tripleo_plan_deploy.py
Normal file
146
tripleo_ansible/ansible_plugins/modules/tripleo_plan_deploy.py
Normal file
@ -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.
|
||||
from heatclient.v1 import client as heatclient
|
||||
from swiftclient import client as swift_client
|
||||
|
||||
from tripleo_common.utils import stack as stack_utils
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: tripleo_plan_deploy
|
||||
|
||||
short_description: Deploy Plan
|
||||
|
||||
version_added: "2.8"
|
||||
|
||||
description:
|
||||
- "Deploy Plan"
|
||||
|
||||
options:
|
||||
container:
|
||||
description:
|
||||
- Overcloud plan container name
|
||||
type: str
|
||||
default: overcloud
|
||||
skip_deploy_identifier:
|
||||
description:
|
||||
- Skip deploy indetifier
|
||||
type: bool
|
||||
default: false
|
||||
timeout_mins:
|
||||
description:
|
||||
- Stack deploy timeout in mins
|
||||
type: int
|
||||
default: 240
|
||||
|
||||
author:
|
||||
- Rabi Mishra (@ramishra)
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Deploy Plan
|
||||
tripleo_plan_deploy:
|
||||
container: overcloud
|
||||
skip_deploy_identifier: false
|
||||
timeout_mins: 240
|
||||
'''
|
||||
|
||||
|
||||
def run_module():
|
||||
result = dict(
|
||||
success=False,
|
||||
changed=False,
|
||||
error="",
|
||||
)
|
||||
|
||||
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 swift_client.Connection(
|
||||
session=session,
|
||||
retries=10,
|
||||
starting_backoff=3,
|
||||
max_backoff=120)
|
||||
|
||||
def get_orchestration_client(session):
|
||||
return heatclient.Client(
|
||||
session=session)
|
||||
|
||||
try:
|
||||
container = module.params.get('container')
|
||||
skip_deploy_identifier = module.params.get('skip_deploy_identifier')
|
||||
timeout_mins = module.params.get('timeout_mins')
|
||||
_, conn = openstack_cloud_from_module(module)
|
||||
session = conn.session
|
||||
|
||||
swift = get_object_client(session)
|
||||
heat = get_orchestration_client(session)
|
||||
stack_utils.deploy_stack(
|
||||
swift, heat,
|
||||
container=container,
|
||||
skip_deploy_identifier=skip_deploy_identifier,
|
||||
timeout_mins=timeout_mins)
|
||||
result['success'] = True
|
||||
result['changed'] = True
|
||||
except Exception as err:
|
||||
result['error'] = str(err)
|
||||
result['msg'] = ("Error updating parameters for plan %s: %s" % (
|
||||
container, 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()
|
95
tripleo_ansible/playbooks/cli-deploy-deployment-plan.yaml
Normal file
95
tripleo_ansible/playbooks/cli-deploy-deployment-plan.yaml
Normal file
@ -0,0 +1,95 @@
|
||||
---
|
||||
# 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: Deploy 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
|
||||
run_validations: false
|
||||
timeout_mins: 240
|
||||
skip_deploy_identifier: false
|
||||
|
||||
pre_tasks:
|
||||
- name: Set ansible_home for for local connection
|
||||
set_fact:
|
||||
ansible_home: "{{ lookup('env', 'HOME') }}"
|
||||
run_once: true
|
||||
when:
|
||||
- (tripleo_target_host is defined) | ternary('ssh', 'local') == 'local'
|
||||
|
||||
tasks:
|
||||
- name: Check if validation enabled
|
||||
command: >
|
||||
hiera tripleo_validations_enabled
|
||||
register: validations_enabled
|
||||
become: true
|
||||
|
||||
- name: Run Validations
|
||||
# 1. tripleo-validations does not work with clouds.yaml
|
||||
# 2. Ignore errors as certain validations in 'pre-deployment'
|
||||
# group i.e tls-everywhere-pre-deployment.yaml would fail.
|
||||
shell: |
|
||||
source "{{ ansible_home }}/stackrc"
|
||||
openstack tripleo validator run --group "pre-deployment"
|
||||
when:
|
||||
- validations_enabled.stdout | bool
|
||||
ignore_errors: true
|
||||
|
||||
- name: Prepare Container images and update plan
|
||||
tripleo_image_params_prepare:
|
||||
container: "{{ container }}"
|
||||
with_roledata: true
|
||||
|
||||
- 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: true
|
||||
|
||||
- name: Deploy Plan
|
||||
tripleo_plan_deploy:
|
||||
container: "{{ container }}"
|
||||
skip_deploy_identifier: "{{ skip_deploy_identifier }}"
|
||||
timeout_mins: "{{ timeout_mins|int }}"
|
||||
|
||||
- name: Wait for stack status
|
||||
command: |
|
||||
openstack --os-cloud undercloud stack show "{{ container }}" -c stack_status
|
||||
register: check_status
|
||||
until: "'IN_PROGRESS' not in check_status.stdout"
|
||||
retries: "{{ (timeout_mins|int * 60 / 15)|int }}"
|
||||
delay: 15
|
Loading…
Reference in New Issue
Block a user