From 61b0981341e71bbcf1e32132affde3d05a8ac84c Mon Sep 17 00:00:00 2001 From: yaakov kuperman Date: Thu, 19 Jul 2018 08:13:16 -0400 Subject: [PATCH] [AWS] check mode for ec2_elb and elb_instance (#42694) what ELBs an instance will be deregistered from prior to actually executing --- lib/ansible/modules/cloud/amazon/ec2_elb.py | 10 ++++++---- lib/ansible/modules/cloud/amazon/elb_instance.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_elb.py b/lib/ansible/modules/cloud/amazon/ec2_elb.py index 102153b8dd6..1a0dfdb2cab 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_elb.py +++ b/lib/ansible/modules/cloud/amazon/ec2_elb.py @@ -332,6 +332,7 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, + supports_check_mode=True ) if not HAS_BOTO: @@ -359,10 +360,11 @@ def main(): msg = "ELB %s does not exist" % elb module.fail_json(msg=msg) - if module.params['state'] == 'present': - elb_man.register(wait, enable_availability_zone, timeout) - elif module.params['state'] == 'absent': - elb_man.deregister(wait, timeout) + if not module.check_mode: + if module.params['state'] == 'present': + elb_man.register(wait, enable_availability_zone, timeout) + elif module.params['state'] == 'absent': + elb_man.deregister(wait, timeout) ansible_facts = {'ec2_elbs': [lb.name for lb in elb_man.lbs]} ec2_facts_result = dict(changed=elb_man.changed, ansible_facts=ansible_facts) diff --git a/lib/ansible/modules/cloud/amazon/elb_instance.py b/lib/ansible/modules/cloud/amazon/elb_instance.py index c5b577d0dba..78323326d2c 100644 --- a/lib/ansible/modules/cloud/amazon/elb_instance.py +++ b/lib/ansible/modules/cloud/amazon/elb_instance.py @@ -328,6 +328,7 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, + supports_check_mode=True ) if not HAS_BOTO: @@ -355,10 +356,11 @@ def main(): msg = "ELB %s does not exist" % elb module.fail_json(msg=msg) - if module.params['state'] == 'present': - elb_man.register(wait, enable_availability_zone, timeout) - elif module.params['state'] == 'absent': - elb_man.deregister(wait, timeout) + if not module.check_mode: + if module.params['state'] == 'present': + elb_man.register(wait, enable_availability_zone, timeout) + elif module.params['state'] == 'absent': + elb_man.deregister(wait, timeout) ansible_facts = {'ec2_elbs': [lb.name for lb in elb_man.lbs]} ec2_facts_result = dict(changed=elb_man.changed, ansible_facts=ansible_facts)