From e2bd4adf6e1a274fa6a72a120309854da649cd73 Mon Sep 17 00:00:00 2001 From: Vasily Angapov Date: Sat, 26 May 2018 10:04:05 +0800 Subject: [PATCH] os_image_facts: add ability to list all Openstack images --- .../modules/cloud/openstack/os_image_facts.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_image_facts.py b/lib/ansible/modules/cloud/openstack/os_image_facts.py index a8c5f458085..c452e3cd8c4 100644 --- a/lib/ansible/modules/cloud/openstack/os_image_facts.py +++ b/lib/ansible/modules/cloud/openstack/os_image_facts.py @@ -28,7 +28,7 @@ options: image: description: - Name or ID of the image - required: true + required: false availability_zone: description: - Ignored. Present for backwards compatibility @@ -49,6 +49,14 @@ EXAMPLES = ''' - name: Show openstack facts debug: var: openstack_image + +# Show all available Openstack images +- name: Retrieve all available Openstack images + os_image_facts: + +- name: Show images + debug: + var: openstack_image ''' RETURN = ''' @@ -134,16 +142,21 @@ from ansible.module_utils.openstack import openstack_full_argument_spec, opensta def main(): argument_spec = openstack_full_argument_spec( - image=dict(required=True), + image=dict(required=False), ) module_kwargs = openstack_module_kwargs() module = AnsibleModule(argument_spec, **module_kwargs) sdk, cloud = openstack_cloud_from_module(module) try: - image = cloud.get_image(module.params['image']) - module.exit_json(changed=False, ansible_facts=dict( - openstack_image=image)) + if module.params['image']: + image = cloud.get_image(module.params['image']) + module.exit_json(changed=False, ansible_facts=dict( + openstack_image=image)) + else: + images = cloud.list_images() + module.exit_json(changed=False, ansible_facts=dict( + openstack_image=images)) except sdk.exceptions.OpenStackCloudException as e: module.fail_json(msg=str(e))