diff --git a/.zuul.yaml b/.zuul.yaml index 7002d002bf72fd4fd95e25ecfa24b82ce30d1c08..83bfbca4f12b329caf9daa450b59f79ecb12507c 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -66,8 +66,8 @@ address_scope auth catalog_service - client_config compute_flavor + config dns dns_zone_info endpoint diff --git a/ci/roles/client_config/tasks/main.yml b/ci/roles/client_config/tasks/main.yml deleted file mode 100644 index 8b5efbcee4193faba45793771aa40815c4fff8fc..0000000000000000000000000000000000000000 --- a/ci/roles/client_config/tasks/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: List all profiles - openstack.cloud.config: - register: list - -# WARNING: This will output sensitive authentication information!!!! -- debug: var=list diff --git a/ci/roles/config/tasks/main.yml b/ci/roles/config/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..6e4f5775a5dbc471a4e910c6cb0a95498e0807c1 --- /dev/null +++ b/ci/roles/config/tasks/main.yml @@ -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) diff --git a/ci/run-collection.yml b/ci/run-collection.yml index 508cedcc62ce4a9b3a654263ac70ae1abe73a5c7..ef7086c3ceaa22a9d5774fdc74bafc18b0f06120 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -7,8 +7,8 @@ - { role: address_scope, tags: address_scope } - { role: auth, tags: auth } - { role: catalog_service, tags: catalog_service } - - { role: client_config, tags: client_config } - { role: compute_flavor, tags: compute_flavor } + - { role: config, tags: config } - { role: dns_zone_info, tags: dns_zone_info } - role: object_container tags: object_container diff --git a/plugins/modules/config.py b/plugins/modules/config.py index 0127a0986274f801754c26517d1744cd39529eac..a928de3fae76ad8390f350d8c98419f6170fd33c 100644 --- a/plugins/modules/config.py +++ b/plugins/modules/config.py @@ -4,43 +4,65 @@ # 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 ''' -EXAMPLES = ''' -- name: Get list of clouds that do not support security groups +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 = 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 @@ -48,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(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))