diff options
Diffstat (limited to 'ansible_collections/openstack/cloud/plugins/modules/config.py')
-rw-r--r-- | ansible_collections/openstack/cloud/plugins/modules/config.py | 83 |
1 files changed, 52 insertions, 31 deletions
diff --git a/ansible_collections/openstack/cloud/plugins/modules/config.py b/ansible_collections/openstack/cloud/plugins/modules/config.py index 94036e499..478555efe 100644 --- a/ansible_collections/openstack/cloud/plugins/modules/config.py +++ b/ansible_collections/openstack/cloud/plugins/modules/config.py @@ -1,45 +1,68 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- # 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) -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: config short_description: Get OpenStack Client config +author: OpenStack Ansible SIG description: - - Get I(openstack) client config data from clouds.yaml or environment -notes: - - Facts are placed in the C(openstack.clouds) variable. + - Get OpenStack cloud credentials and configuration, + e.g. from clouds.yaml and environment variables. options: clouds: description: - - List of clouds to limit the return list to. No value means return - information on all configured clouds - required: false + - List of clouds to limit the return list to. + - When I(clouds) is not defined, then data + is returned for all configured clouds. default: [] type: list elements: str requirements: - - "python >= 3.6" - - "openstacksdk" -author: OpenStack Ansible SIG + - "python >= 3.6" + - "openstacksdk >= 1.0.0" +''' + +RETURN = r''' +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 = ''' -- name: Get list of clouds that do not support security groups +EXAMPLES = r''' +- name: Read configuration of all defined clouds openstack.cloud.config: + register: config -- debug: - var: "{{ item }}" - with_items: "{{ openstack.clouds | rejectattr('secgroup_source', 'none') | list }}" +- name: Print clouds which do not support security groups + loop: "{{ config.clouds }}" + 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: clouds: + - devstack - mordred ''' +from ansible.module_utils.basic import AnsibleModule + try: import openstack.config from openstack import exceptions @@ -47,28 +70,26 @@ try: except ImportError: HAS_OPENSTACKSDK = False -from ansible.module_utils.basic import AnsibleModule - def main(): - module = AnsibleModule(argument_spec=dict( - clouds=dict(required=False, type='list', default=[], elements='str'), - )) + module = AnsibleModule( + argument_spec=dict( + clouds=dict(type='list', default=[], elements='str'), + ) + ) if not HAS_OPENSTACKSDK: module.fail_json(msg='openstacksdk is required for this module') - p = module.params - try: - config = openstack.config.OpenStackConfig() - clouds = [] - for cloud in config.get_all_clouds(): - if not p['clouds'] or cloud.name in p['clouds']: - cloud.config['name'] = cloud.name - clouds.append(cloud.config) - module.exit_json(ansible_facts=dict(openstack=dict(clouds=clouds))) - except exceptions.ConfigException as e: + clouds = [dict(name=cloud.name, config=cloud.config) + for cloud in openstack.config.OpenStackConfig().get_all() + if not module.params['clouds'] + or cloud.name in module.params['clouds']] + + module.exit_json(changed=False, clouds=clouds) + + except exceptions.SDKException as e: module.fail_json(msg=str(e)) |