2021-01-06 12:00:12 +01:00
|
|
|
#!/usr/bin/python
|
2022-07-28 09:19:14 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-01-06 12:00:12 +01:00
|
|
|
|
|
|
|
# Copyright (c) 2020, Sagi Shnaidman <sshnaidm@redhat.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
2022-09-28 12:21:32 +02:00
|
|
|
DOCUMENTATION = r'''
|
2021-01-06 12:00:12 +01:00
|
|
|
---
|
|
|
|
module: stack_info
|
2022-09-28 12:21:32 +02:00
|
|
|
short_description: Retrieve information about Heat stacks
|
2021-01-06 12:00:12 +01:00
|
|
|
author: OpenStack Ansible SIG
|
|
|
|
description:
|
2022-09-28 12:21:32 +02:00
|
|
|
- Get information about Heat stack in OpenStack
|
2021-01-06 12:00:12 +01:00
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
2022-09-28 12:21:32 +02:00
|
|
|
- Name of the stack.
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
2022-09-28 12:21:32 +02:00
|
|
|
owner:
|
2021-01-06 12:00:12 +01:00
|
|
|
description:
|
2022-09-28 12:21:32 +02:00
|
|
|
- Name or ID of the parent stack.
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
2022-09-28 12:21:32 +02:00
|
|
|
aliases: ['owner_id']
|
|
|
|
project:
|
2021-01-06 12:00:12 +01:00
|
|
|
description:
|
2022-09-28 12:21:32 +02:00
|
|
|
- Name or ID of the project.
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
2022-09-28 12:21:32 +02:00
|
|
|
aliases: ['project_id']
|
|
|
|
status:
|
2021-01-06 12:00:12 +01:00
|
|
|
description:
|
2022-09-28 12:21:32 +02:00
|
|
|
- Status of the stack such as C(available)
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- openstack.cloud.openstack
|
|
|
|
'''
|
|
|
|
|
2022-09-28 12:21:32 +02:00
|
|
|
EXAMPLES = r'''
|
|
|
|
- name: Fetch all Heat stacks
|
|
|
|
openstack.cloud.stack_info:
|
|
|
|
cloud: devstack
|
|
|
|
|
|
|
|
- name: Fetch a single Heat stack
|
|
|
|
openstack.cloud.stack_info:
|
|
|
|
cloud: devstack
|
|
|
|
name: my_stack
|
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = r'''
|
2021-01-06 12:00:12 +01:00
|
|
|
stacks:
|
|
|
|
description: List of dictionaries describing stacks.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
returned: always.
|
|
|
|
contains:
|
2022-09-28 12:21:32 +02:00
|
|
|
added:
|
|
|
|
description: List of resource objects that will be added.
|
|
|
|
type: list
|
|
|
|
capabilities:
|
|
|
|
description: AWS compatible template listing capabilities.
|
|
|
|
type: list
|
|
|
|
created_at:
|
|
|
|
description: Time when created.
|
|
|
|
type: str
|
|
|
|
sample: "2016-07-05T17:38:12Z"
|
|
|
|
deleted:
|
|
|
|
description: A list of resource objects that will be deleted.
|
|
|
|
type: list
|
|
|
|
deleted_at:
|
|
|
|
description: Time when the deleted.
|
|
|
|
type: str
|
|
|
|
sample: "2016-07-05T17:38:12Z"
|
|
|
|
description:
|
|
|
|
description: >
|
|
|
|
Description of the Stack provided in the heat
|
|
|
|
template.
|
|
|
|
type: str
|
|
|
|
sample: "HOT template to create a new instance and networks"
|
|
|
|
environment:
|
|
|
|
description: A JSON environment for the stack.
|
|
|
|
type: dict
|
|
|
|
environment_files:
|
|
|
|
description: >
|
|
|
|
An ordered list of names for environment files found
|
|
|
|
in the files dict.
|
|
|
|
type: list
|
|
|
|
files:
|
|
|
|
description: >
|
|
|
|
Additional files referenced in the template or
|
|
|
|
the environment
|
|
|
|
type: dict
|
|
|
|
files_container:
|
|
|
|
description: >
|
|
|
|
Name of swift container with child templates and
|
|
|
|
files.
|
|
|
|
type: str
|
2021-01-06 12:00:12 +01:00
|
|
|
id:
|
2022-09-28 12:21:32 +02:00
|
|
|
description: Stack ID.
|
|
|
|
type: str
|
|
|
|
sample: "97a3f543-8136-4570-920e-fd7605c989d6"
|
|
|
|
is_rollback_disabled:
|
|
|
|
description: Whether the stack will support a rollback.
|
|
|
|
type: bool
|
|
|
|
links:
|
|
|
|
description: Links to the current Stack.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
sample: "[{'href': 'http://foo:8004/v1/7f6a/stacks/test-stack/
|
|
|
|
97a3f543-8136-4570-920e-fd7605c989d6']"
|
|
|
|
name:
|
|
|
|
description: Name of the Stack
|
|
|
|
type: str
|
|
|
|
sample: "test-stack"
|
|
|
|
notification_topics:
|
|
|
|
description: Stack related events.
|
|
|
|
type: str
|
|
|
|
sample: "HOT template to create a new instance and networks"
|
|
|
|
outputs:
|
|
|
|
description: Output returned by the Stack.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
sample: "[{'description': 'IP of server1 in private network',
|
|
|
|
'output_key': 'server1_private_ip',
|
|
|
|
'output_value': '10.1.10.103'}]"
|
|
|
|
owner_id:
|
|
|
|
description: The ID of the owner stack if any.
|
|
|
|
type: str
|
|
|
|
parameters:
|
|
|
|
description: Parameters of the current Stack
|
|
|
|
type: dict
|
|
|
|
sample: "{'OS::project_id': '7f6a3a3e01164a4eb4eecb2ab7742101',
|
|
|
|
'OS::stack_id': '97a3f543-8136-4570-920e-fd7605c989d6',
|
|
|
|
'OS::stack_name': 'test-stack',
|
|
|
|
'stack_status': 'CREATE_COMPLETE',
|
|
|
|
'stack_status_reason':
|
|
|
|
'Stack CREATE completed successfully',
|
|
|
|
'status': 'COMPLETE',
|
|
|
|
'template_description':
|
|
|
|
'HOT template to create a new instance and nets',
|
|
|
|
'timeout_mins': 60,
|
|
|
|
'updated_time': null}"
|
|
|
|
parent_id:
|
|
|
|
description: The ID of the parent stack if any.
|
|
|
|
type: str
|
|
|
|
replaced:
|
|
|
|
description: A list of resource objects that will be replaced.
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
|
|
|
status:
|
2022-09-28 12:21:32 +02:00
|
|
|
description: stack status.
|
|
|
|
type: str
|
|
|
|
status_reason:
|
|
|
|
description: >
|
|
|
|
Explaining how the stack transits to its current
|
|
|
|
status.
|
|
|
|
type: str
|
|
|
|
tags:
|
|
|
|
description: A list of strings used as tags on the stack
|
|
|
|
type: list
|
|
|
|
template:
|
|
|
|
description: A dict containing the template use for stack creation.
|
|
|
|
type: dict
|
|
|
|
template_description:
|
|
|
|
description: Stack template description text.
|
|
|
|
type: str
|
|
|
|
template_url:
|
|
|
|
description: The URL where a stack template can be found.
|
|
|
|
type: str
|
|
|
|
timeout_mins:
|
|
|
|
description: Stack operation timeout in minutes.
|
|
|
|
type: str
|
|
|
|
unchanged:
|
|
|
|
description: >
|
|
|
|
A list of resource objects that will remain unchanged
|
|
|
|
if a stack.
|
|
|
|
type: list
|
|
|
|
updated:
|
|
|
|
description: >
|
|
|
|
A list of resource objects that will have their
|
|
|
|
properties updated.
|
|
|
|
type: list
|
|
|
|
updated_at:
|
|
|
|
description: Timestamp of last update on the stack.
|
|
|
|
type: str
|
|
|
|
user_project_id:
|
|
|
|
description: The ID of the user project created for this stack.
|
2021-01-06 12:00:12 +01:00
|
|
|
type: str
|
|
|
|
'''
|
|
|
|
|
|
|
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
|
|
|
|
|
|
|
|
|
|
|
class StackInfoModule(OpenStackModule):
|
|
|
|
argument_spec = dict(
|
2022-07-27 12:39:44 +02:00
|
|
|
name=dict(),
|
2022-09-28 12:21:32 +02:00
|
|
|
owner=dict(aliases=['owner_id']),
|
|
|
|
project=dict(aliases=['project_id']),
|
2022-07-27 12:39:44 +02:00
|
|
|
status=dict(),
|
2021-01-06 12:00:12 +01:00
|
|
|
)
|
2022-09-28 12:21:32 +02:00
|
|
|
|
2021-08-16 13:21:27 +03:00
|
|
|
module_kwargs = dict(
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
2021-01-06 12:00:12 +01:00
|
|
|
|
|
|
|
def run(self):
|
2022-09-28 12:21:32 +02:00
|
|
|
kwargs = {}
|
|
|
|
|
|
|
|
owner_name_or_id = self.params['owner']
|
|
|
|
if owner_name_or_id:
|
|
|
|
owner = self.conn.orchestration.find_stack(owner_name_or_id)
|
|
|
|
if owner:
|
|
|
|
kwargs['owner_id'] = owner['id']
|
|
|
|
else:
|
|
|
|
# Owner could not be found so return empty list of stacks
|
|
|
|
# because *_info modules never raise errors on missing
|
|
|
|
# resources
|
|
|
|
self.exit_json(changed=False, stacks=[])
|
|
|
|
|
|
|
|
project_name_or_id = self.params['project']
|
|
|
|
if project_name_or_id:
|
|
|
|
project = self.conn.identity.find_project(project_name_or_id)
|
|
|
|
if project:
|
|
|
|
kwargs['project_id'] = project['id']
|
|
|
|
else:
|
|
|
|
# Project could not be found so return empty list of stacks
|
|
|
|
# because *_info modules never raise errors on missing
|
|
|
|
# resources
|
|
|
|
self.exit_json(changed=False, stacks=[])
|
|
|
|
|
|
|
|
for k in ['name', 'status']:
|
|
|
|
if self.params[k] is not None:
|
|
|
|
kwargs[k] = self.params[k]
|
|
|
|
|
|
|
|
stacks = [stack.to_dict(computed=False)
|
|
|
|
for stack in self.conn.orchestration.stacks(**kwargs)]
|
|
|
|
|
|
|
|
self.exit_json(changed=False, stacks=stacks)
|
2021-01-06 12:00:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = StackInfoModule()
|
|
|
|
module()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|