From 60102e36e28f07b1e6b44362c177be8e2f086845 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 17 Jun 2015 07:39:27 -0400 Subject: [PATCH] Return rule object --- .../modules/cloud/openstack/os_security_group_rule.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_security_group_rule.py b/lib/ansible/modules/cloud/openstack/os_security_group_rule.py index 2073970fcb9..ac90e1898c4 100644 --- a/lib/ansible/modules/cloud/openstack/os_security_group_rule.py +++ b/lib/ansible/modules/cloud/openstack/os_security_group_rule.py @@ -177,8 +177,9 @@ def main(): module.fail_json(msg='Could not find security group %s' % security_group) - if not _find_matching_rule(module, secgroup): - cloud.create_security_group_rule( + rule = _find_matching_rule(module, secgroup): + if not rule: + rule = cloud.create_security_group_rule( secgroup['id'], port_range_min=module.params['port_range_min'], port_range_max=module.params['port_range_max'], @@ -189,6 +190,7 @@ def main(): ethertype=module.params['ethertype'] ) changed = True + module.exit_json(changed=changed, rule=rule, id=rule.id) if state == 'absent' and secgroup: rule = _find_matching_rule(module, secgroup) @@ -196,7 +198,7 @@ def main(): cloud.delete_security_group_rule(rule['id']) changed = True - module.exit_json(changed=changed) + module.exit_json(changed=changed) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message)