os_image_facts: add ability to list all Openstack images
This commit is contained in:
parent
02cb0fd30d
commit
e2bd4adf6e
1 changed files with 18 additions and 5 deletions
|
@ -28,7 +28,7 @@ options:
|
||||||
image:
|
image:
|
||||||
description:
|
description:
|
||||||
- Name or ID of the image
|
- Name or ID of the image
|
||||||
required: true
|
required: false
|
||||||
availability_zone:
|
availability_zone:
|
||||||
description:
|
description:
|
||||||
- Ignored. Present for backwards compatibility
|
- Ignored. Present for backwards compatibility
|
||||||
|
@ -49,6 +49,14 @@ EXAMPLES = '''
|
||||||
- name: Show openstack facts
|
- name: Show openstack facts
|
||||||
debug:
|
debug:
|
||||||
var: openstack_image
|
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 = '''
|
RETURN = '''
|
||||||
|
@ -134,16 +142,21 @@ from ansible.module_utils.openstack import openstack_full_argument_spec, opensta
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
argument_spec = openstack_full_argument_spec(
|
argument_spec = openstack_full_argument_spec(
|
||||||
image=dict(required=True),
|
image=dict(required=False),
|
||||||
)
|
)
|
||||||
module_kwargs = openstack_module_kwargs()
|
module_kwargs = openstack_module_kwargs()
|
||||||
module = AnsibleModule(argument_spec, **module_kwargs)
|
module = AnsibleModule(argument_spec, **module_kwargs)
|
||||||
|
|
||||||
sdk, cloud = openstack_cloud_from_module(module)
|
sdk, cloud = openstack_cloud_from_module(module)
|
||||||
try:
|
try:
|
||||||
image = cloud.get_image(module.params['image'])
|
if module.params['image']:
|
||||||
module.exit_json(changed=False, ansible_facts=dict(
|
image = cloud.get_image(module.params['image'])
|
||||||
openstack_image=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:
|
except sdk.exceptions.OpenStackCloudException as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
Loading…
Reference in a new issue