os_image_facts: add ability to filter Openstack images based on properties

This commit is contained in:
Pavel Holica 2019-02-13 08:21:19 +01:00 committed by Gonéri Le Bouder
parent 58edfec145
commit 89744b72d3

View file

@ -29,6 +29,12 @@ options:
description:
- Name or ID of the image
required: false
properties:
description:
- Dict of properties of the images used for query
type: dict
required: false
version_added: '2.9'
availability_zone:
description:
- Ignored. Present for backwards compatibility
@ -56,6 +62,17 @@ EXAMPLES = '''
os_image_info:
register: result
- name: Show images
debug:
msg: "{{ result.openstack_image }}"
# Show images matching requested properties
- name: Retrieve images having properties with desired values
os_image_facts:
properties:
some_property: some_value
OtherProp: OtherVal
- name: Show images
debug:
msg: "{{ result.openstack_image }}"
@ -145,6 +162,7 @@ def main():
argument_spec = openstack_full_argument_spec(
image=dict(required=False),
properties=dict(default=None, type='dict'),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
@ -163,7 +181,7 @@ def main():
else:
module.exit_json(changed=False, openstack_image=image)
else:
images = cloud.list_images()
images = cloud.search_images(filters=module.params['properties'])
if is_old_facts:
module.exit_json(changed=False, ansible_facts=dict(
openstack_image=images))