mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 22:03:09 +00:00
Refactored config module
Change-Id: I7ba626e2ef2a108bf79cacd8d6ee0735b8a0bdeb
This commit is contained in:
@@ -66,8 +66,8 @@
|
|||||||
address_scope
|
address_scope
|
||||||
auth
|
auth
|
||||||
catalog_service
|
catalog_service
|
||||||
client_config
|
|
||||||
compute_flavor
|
compute_flavor
|
||||||
|
config
|
||||||
dns
|
dns
|
||||||
dns_zone_info
|
dns_zone_info
|
||||||
endpoint
|
endpoint
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
- name: List all profiles
|
|
||||||
openstack.cloud.config:
|
|
||||||
register: list
|
|
||||||
|
|
||||||
# WARNING: This will output sensitive authentication information!!!!
|
|
||||||
- debug: var=list
|
|
||||||
10
ci/roles/config/tasks/main.yml
Normal file
10
ci/roles/config/tasks/main.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
- name: List all cloud profiles
|
||||||
|
openstack.cloud.config:
|
||||||
|
register: config
|
||||||
|
# WARNING: This will output sensitive authentication information!!!!
|
||||||
|
|
||||||
|
- name: Assert config module
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- cloud in (config.clouds | map(attribute='name') | list)
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
- { role: address_scope, tags: address_scope }
|
- { role: address_scope, tags: address_scope }
|
||||||
- { role: auth, tags: auth }
|
- { role: auth, tags: auth }
|
||||||
- { role: catalog_service, tags: catalog_service }
|
- { role: catalog_service, tags: catalog_service }
|
||||||
- { role: client_config, tags: client_config }
|
|
||||||
- { role: compute_flavor, tags: compute_flavor }
|
- { role: compute_flavor, tags: compute_flavor }
|
||||||
|
- { role: config, tags: config }
|
||||||
- { role: dns_zone_info, tags: dns_zone_info }
|
- { role: dns_zone_info, tags: dns_zone_info }
|
||||||
- role: object_container
|
- role: object_container
|
||||||
tags: object_container
|
tags: object_container
|
||||||
|
|||||||
@@ -4,43 +4,65 @@
|
|||||||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: config
|
module: config
|
||||||
short_description: Get OpenStack Client config
|
short_description: Get OpenStack Client config
|
||||||
|
author: OpenStack Ansible SIG
|
||||||
description:
|
description:
|
||||||
- Get I(openstack) client config data from clouds.yaml or environment
|
- Get OpenStack cloud credentials and configuration,
|
||||||
notes:
|
e.g. from clouds.yaml and environment variables.
|
||||||
- Facts are placed in the C(openstack.clouds) variable.
|
|
||||||
options:
|
options:
|
||||||
clouds:
|
clouds:
|
||||||
description:
|
description:
|
||||||
- List of clouds to limit the return list to. No value means return
|
- List of clouds to limit the return list to.
|
||||||
information on all configured clouds
|
- When I(clouds) is not defined, then data
|
||||||
required: false
|
is returned for all configured clouds.
|
||||||
default: []
|
default: []
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk"
|
- "openstacksdk"
|
||||||
author: OpenStack Ansible SIG
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
RETURN = r'''
|
||||||
- name: Get list of clouds that do not support security groups
|
clouds:
|
||||||
|
description: List of OpenStack cloud configurations.
|
||||||
|
returned: always
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
contains:
|
||||||
|
name:
|
||||||
|
description: Name of the cloud.
|
||||||
|
type: str
|
||||||
|
config:
|
||||||
|
description: A dict of configuration values for the CloudRegion and
|
||||||
|
its services. The key for a ${config_option} for a
|
||||||
|
specific ${service} should be ${service}_${config_option}.
|
||||||
|
type: dict
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = r'''
|
||||||
|
- name: Read configuration of all defined clouds
|
||||||
openstack.cloud.config:
|
openstack.cloud.config:
|
||||||
|
register: config
|
||||||
|
|
||||||
- debug:
|
- name: Print clouds which do not support security groups
|
||||||
var: "{{ item }}"
|
loop: "{{ config.clouds }}"
|
||||||
with_items: "{{ openstack.clouds | rejectattr('secgroup_source', 'none') | list }}"
|
when: item.config.secgroup_source|default(None) != None
|
||||||
|
debug:
|
||||||
|
var: item
|
||||||
|
|
||||||
- name: Get the information back just about the mordred cloud
|
- name: Read configuration of a two specific clouds
|
||||||
openstack.cloud.config:
|
openstack.cloud.config:
|
||||||
clouds:
|
clouds:
|
||||||
|
- devstack
|
||||||
- mordred
|
- mordred
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import openstack.config
|
import openstack.config
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
@@ -48,28 +70,26 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_OPENSTACKSDK = False
|
HAS_OPENSTACKSDK = False
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=dict(
|
module = AnsibleModule(
|
||||||
clouds=dict(type='list', default=[], elements='str'),
|
argument_spec=dict(
|
||||||
))
|
clouds=dict(type='list', default=[], elements='str'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_OPENSTACKSDK:
|
if not HAS_OPENSTACKSDK:
|
||||||
module.fail_json(msg='openstacksdk is required for this module')
|
module.fail_json(msg='openstacksdk is required for this module')
|
||||||
|
|
||||||
p = module.params
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = openstack.config.OpenStackConfig()
|
clouds = [dict(name=cloud.name, config=cloud.config)
|
||||||
clouds = []
|
for cloud in openstack.config.OpenStackConfig().get_all()
|
||||||
for cloud in config.get_all_clouds():
|
if not module.params['clouds']
|
||||||
if not p['clouds'] or cloud.name in p['clouds']:
|
or cloud.name in module.params['clouds']]
|
||||||
cloud.config['name'] = cloud.name
|
|
||||||
clouds.append(cloud.config)
|
module.exit_json(changed=False, clouds=clouds)
|
||||||
module.exit_json(ansible_facts=dict(openstack=dict(clouds=clouds)))
|
|
||||||
except exceptions.ConfigException as e:
|
except exceptions.SDKException as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user