From 2af105bcbc8d649d13311d583368617e5ac4cf98 Mon Sep 17 00:00:00 2001 From: HAMSIK Adam Date: Thu, 6 Aug 2015 16:51:36 +0200 Subject: [PATCH] Convert enabled value to boolean to actually work, make sure we can set expiration period to 0(None) to disable it --- lib/ansible/modules/cloud/amazon/ec2_elb_lb.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py index fa85faed436..85901abfd91 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py +++ b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py @@ -809,21 +809,25 @@ class ElbManager(object): if self.stickiness['type'] == 'loadbalancer': policy = [] policy_type = 'LBCookieStickinessPolicyType' - if self.stickiness['enabled'] == True: + + if self.module.boolean(self.stickiness['enabled']) == True: if 'expiration' not in self.stickiness: self.module.fail_json(msg='expiration must be set when type is loadbalancer') + expiration = self.stickiness['expiration'] if self.stickiness['expiration'] is not 0 else None + policy_attrs = { 'type': policy_type, 'attr': 'lb_cookie_stickiness_policies', 'method': 'create_lb_cookie_stickiness_policy', 'dict_key': 'cookie_expiration_period', - 'param_value': self.stickiness['expiration'] + 'param_value': expiration } policy.append(self._policy_name(policy_attrs['type'])) + self._set_stickiness_policy(elb_info, listeners_dict, policy, **policy_attrs) - elif self.stickiness['enabled'] == False: + elif self.module.boolean(self.stickiness['enabled']) == False: if len(elb_info.policies.lb_cookie_stickiness_policies): if elb_info.policies.lb_cookie_stickiness_policies[0].policy_name == self._policy_name(policy_type): self.changed = True @@ -835,7 +839,7 @@ class ElbManager(object): elif self.stickiness['type'] == 'application': policy = [] policy_type = 'AppCookieStickinessPolicyType' - if self.stickiness['enabled'] == True: + if self.module.boolean(self.stickiness['enabled']) == True: if 'cookie' not in self.stickiness: self.module.fail_json(msg='cookie must be set when type is application') @@ -849,7 +853,7 @@ class ElbManager(object): } policy.append(self._policy_name(policy_attrs['type'])) self._set_stickiness_policy(elb_info, listeners_dict, policy, **policy_attrs) - elif self.stickiness['enabled'] == False: + elif self.module.boolean(self.stickiness['enabled']) == False: if len(elb_info.policies.app_cookie_stickiness_policies): if elb_info.policies.app_cookie_stickiness_policies[0].policy_name == self._policy_name(policy_type): self.changed = True