From ef22008cac3dae41d7318cc9b110b8c32925ccc4 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 17 Jun 2015 04:20:42 -0400 Subject: [PATCH 1/3] Return secgroup, not just id --- cloud/openstack/os_security_group.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud/openstack/os_security_group.py b/cloud/openstack/os_security_group.py index a3d1262d6fe..67730a252f1 100644 --- a/cloud/openstack/os_security_group.py +++ b/cloud/openstack/os_security_group.py @@ -117,12 +117,14 @@ def main(): if state == 'present': if not secgroup: secgroup = cloud.create_security_group(name, description) - module.exit_json(changed=True, id=secgroup['id']) + module.exit_json( + changed=True, id=secgroup.id, secgroup=secgroup) else: if _needs_update(module, secgroup): secgroup = cloud.update_security_group( secgroup['id'], description=description) - module.exit_json(changed=True, id=secgroup['id']) + module.exit_json( + changed=True, id=secgroup.id, secgroup=secgroup) else: module.exit_json(changed=False) From 1a11f07d2957567dfd95e59bfaaa966b8785b4f2 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 17 Jun 2015 08:02:34 -0400 Subject: [PATCH 2/3] Return the secgroup for all present states --- cloud/openstack/os_security_group.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cloud/openstack/os_security_group.py b/cloud/openstack/os_security_group.py index 67730a252f1..268b2563d33 100644 --- a/cloud/openstack/os_security_group.py +++ b/cloud/openstack/os_security_group.py @@ -115,18 +115,17 @@ def main(): module.exit_json(changed=_system_state_change(module, secgroup)) if state == 'present': + changed = False if not secgroup: secgroup = cloud.create_security_group(name, description) - module.exit_json( - changed=True, id=secgroup.id, secgroup=secgroup) + changed = True else: if _needs_update(module, secgroup): secgroup = cloud.update_security_group( secgroup['id'], description=description) - module.exit_json( - changed=True, id=secgroup.id, secgroup=secgroup) - else: - module.exit_json(changed=False) + changed = True + module.exit_json( + changed=True, id=secgroup.id, secgroup=secgroup) if state == 'absent': if not secgroup: From d8c51a67f3d0ef86ca6b7b43f8b0e1556e62e520 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 17 Jun 2015 08:47:14 -0400 Subject: [PATCH 3/3] Actually use changed variable --- cloud/openstack/os_security_group.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cloud/openstack/os_security_group.py b/cloud/openstack/os_security_group.py index 268b2563d33..51e7df772a1 100644 --- a/cloud/openstack/os_security_group.py +++ b/cloud/openstack/os_security_group.py @@ -114,8 +114,8 @@ def main(): if module.check_mode: module.exit_json(changed=_system_state_change(module, secgroup)) + changed = False if state == 'present': - changed = False if not secgroup: secgroup = cloud.create_security_group(name, description) changed = True @@ -125,14 +125,13 @@ def main(): secgroup['id'], description=description) changed = True module.exit_json( - changed=True, id=secgroup.id, secgroup=secgroup) + changed=changed, id=secgroup.id, secgroup=secgroup) if state == 'absent': - if not secgroup: - module.exit_json(changed=False) - else: + if secgroup: cloud.delete_security_group(secgroup['id']) - module.exit_json(changed=True) + changed=True + module.exit_json(changed=changed) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message)