diff --git a/lib/ansible/modules/cloud/openstack/README.md b/lib/ansible/modules/cloud/openstack/README.md index a9b22234add..4a872b11954 100644 --- a/lib/ansible/modules/cloud/openstack/README.md +++ b/lib/ansible/modules/cloud/openstack/README.md @@ -21,6 +21,13 @@ Naming * If the module is one that a cloud admin and a cloud consumer could both use, the cloud consumer rules apply. +Interface +--------- + +* If the resource being managed has an id, it should be returned. +* If the resource being managed has an associated object more complex than + an id, it should also be returned. + Interoperability ---------------- diff --git a/lib/ansible/modules/cloud/openstack/os_image.py b/lib/ansible/modules/cloud/openstack/os_image.py index 115a3f2b4f8..4687ce5e972 100644 --- a/lib/ansible/modules/cloud/openstack/os_image.py +++ b/lib/ansible/modules/cloud/openstack/os_image.py @@ -148,7 +148,7 @@ def main(): if module.params['state'] == 'present': if not image: - result = cloud.create_image( + image = cloud.create_image( name=module.params['name'], filename=module.params['filename'], disk_format=module.params['disk_format'], @@ -158,26 +158,26 @@ def main(): ) changed = True if not module.params['wait']: - module.exit_json(changed=changed, result=result) - image = cloud.get_image(name_or_id=result['id']) + module.exit_json(changed=changed, image=image, id=image.id) cloud.update_image_properties( image=image, kernel=module.params['kernel'], ramdisk=module.params['ramdisk'], **module.params['properties']) + image = cloud.get_image(name_or_id=image.id) + module.exit_json(changed=changed, image=image, id=image.id) elif module.params['state'] == 'absent': if not image: - module.exit_json(changed=False, result="success") + changed = False else: cloud.delete_image( name_or_id=module.params['name'], wait=module.params['wait'], timeout=module.params['timeout']) changed = True - - module.exit_json(changed=changed, id=image.id, result="success") + module.exit_json(changed=changed) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message, extra_data=e.extra_data) diff --git a/lib/ansible/modules/cloud/openstack/os_network.py b/lib/ansible/modules/cloud/openstack/os_network.py index 9c6174462f7..75c431493f6 100644 --- a/lib/ansible/modules/cloud/openstack/os_network.py +++ b/lib/ansible/modules/cloud/openstack/os_network.py @@ -88,16 +88,14 @@ def main(): if state == 'present': if not net: net = cloud.create_network(name, shared, admin_state_up) - module.exit_json(changed=True, result="Created", id=net['id']) - else: - module.exit_json(changed=False, result="Success", id=net['id']) + module.exit_json(changed=False, network=net, id=net['id']) elif state == 'absent': if not net: - module.exit_json(changed=False, result="Success") + module.exit_json(changed=False) else: cloud.delete_network(name) - module.exit_json(changed=True, result="Deleted") + module.exit_json(changed=True) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message) diff --git a/lib/ansible/modules/cloud/openstack/os_object.py b/lib/ansible/modules/cloud/openstack/os_object.py index ed58bb1e705..8243f59e4b3 100644 --- a/lib/ansible/modules/cloud/openstack/os_object.py +++ b/lib/ansible/modules/cloud/openstack/os_object.py @@ -115,7 +115,7 @@ def main(): changed = process_object(cloud, **module.params) - module.exit_json(changed=changed, result="success") + module.exit_json(changed=changed) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message) diff --git a/lib/ansible/modules/cloud/openstack/os_server.py b/lib/ansible/modules/cloud/openstack/os_server.py index 73b30e89913..e029b323cdd 100644 --- a/lib/ansible/modules/cloud/openstack/os_server.py +++ b/lib/ansible/modules/cloud/openstack/os_server.py @@ -241,7 +241,8 @@ EXAMPLES = ''' def _exit_hostvars(module, cloud, server, changed=True): hostvars = meta.get_hostvars_from_server(cloud, server) - module.exit_json(changed=changed, id=server.id, openstack=hostvars) + module.exit_json( + changed=changed, server=server, id=server.id, openstack=hostvars) def _network_args(module, cloud): diff --git a/lib/ansible/modules/cloud/openstack/os_subnet.py b/lib/ansible/modules/cloud/openstack/os_subnet.py index 54672b35ffb..f96ce9fd633 100644 --- a/lib/ansible/modules/cloud/openstack/os_subnet.py +++ b/lib/ansible/modules/cloud/openstack/os_subnet.py @@ -227,7 +227,7 @@ def main(): dns_nameservers=dns, allocation_pools=pool, host_routes=host_routes) - module.exit_json(changed=True, result="created") + changed = True else: if _needs_update(subnet, module): cloud.update_subnet(subnet['id'], @@ -237,16 +237,18 @@ def main(): dns_nameservers=dns, allocation_pools=pool, host_routes=host_routes) - module.exit_json(changed=True, result="updated") + changed = True else: - module.exit_json(changed=False, result="success") + changed = False + module.exit_json(changed=changed) elif state == 'absent': if not subnet: - module.exit_json(changed=False, result="success") + changed = False else: + changed = True cloud.delete_subnet(subnet_name) - module.exit_json(changed=True, result="deleted") + module.exit_json(changed=changed) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message) diff --git a/lib/ansible/modules/cloud/openstack/os_volume.py b/lib/ansible/modules/cloud/openstack/os_volume.py index d98f86acfaa..fced3d61e47 100644 --- a/lib/ansible/modules/cloud/openstack/os_volume.py +++ b/lib/ansible/modules/cloud/openstack/os_volume.py @@ -89,7 +89,7 @@ EXAMPLES = ''' def _present_volume(module, cloud): if cloud.volume_exists(module.params['display_name']): v = cloud.get_volume(module.params['display_name']) - module.exit_json(changed=False, id=v['id']) + module.exit_json(changed=False, id=v['id'], volume=v) volume_args = dict( size=module.params['size'], @@ -106,7 +106,7 @@ def _present_volume(module, cloud): volume = cloud.create_volume( wait=module.params['wait'], timeout=module.params['timeout'], **volume_args) - module.exit_json(changed=True, id=volume['id']) + module.exit_json(changed=True, id=volume['id'], volume=volume) def _absent_volume(module, cloud): @@ -116,8 +116,8 @@ def _absent_volume(module, cloud): wait=module.params['wait'], timeout=module.params['timeout']) except shade.OpenStackCloudTimeout: - module.exit_json(changed=False, result="Volume deletion timed-out") - module.exit_json(changed=True, result='Volume Deleted') + module.exit_json(changed=False) + module.exit_json(changed=True) def main():