os_image_facts: add ability to list all Openstack images

pull/40741/head
Vasily Angapov 7 years ago committed by Monty Taylor
parent 02cb0fd30d
commit e2bd4adf6e

@ -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))

Loading…
Cancel
Save