Repository: ansible/ansible

Issue:
ec2_elb_lb: Numeric parameter stickiness['expiration'] passed to module as string and fails test
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_elb_lb.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.1.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan  5 2017, 16:03:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

also exists on 2.2.0.0
```

##### CONFIGURATION
standard

##### OS / ENVIRONMENT
MacOS/Linux

##### SUMMARY
setting stickiness.expiration to 0 in the module should be converted to None.
it doesn't because the test `stickiness['expiration'] is not 0` fails since stickiness['expiration'] is "0" for some odd reason. this makes the value sent to aws a 0 instead of a None which is not legal on amazon side as value for expiration.

##### STEPS TO REPRODUCE
simply try to create an ELB using the ec2_elb_lb module

https://gist.github.com/hackndoes/925e461767d4b26a0e6d817d558070ed

https://gist.github.com/hackndoes/619b9000dd75c558b352f2709520d3ff

##### EXPECTED RESULTS
creation of LB will succeed

##### ACTUAL RESULTS
inside first gist




ec2_elb_lb: Numeric parameter stickiness['expiration'] passed to module as string and fails test
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_elb_lb.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.1.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan  5 2017, 16:03:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

also exists on 2.2.0.0
```

##### CONFIGURATION
standard

##### OS / ENVIRONMENT
MacOS/Linux

##### SUMMARY
setting stickiness.expiration to 0 in the module should be converted to None.
it doesn't because the test `stickiness['expiration'] is not 0` fails since stickiness['expiration'] is "0" for some odd reason. this makes the value sent to aws a 0 instead of a None which is not legal on amazon side as value for expiration.

##### STEPS TO REPRODUCE
simply try to create an ELB using the ec2_elb_lb module

https://gist.github.com/hackndoes/925e461767d4b26a0e6d817d558070ed

https://gist.github.com/hackndoes/619b9000dd75c558b352f2709520d3ff

##### EXPECTED RESULTS
creation of LB will succeed

##### ACTUAL RESULTS
inside first gist






Discussion:
cc @jarv
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @jsdalton
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @jarv
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @jsdalton
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/elb_classic_lb.py b/lib/ansible/modules/cloud/amazon/elb_classic_lb.py
--- a/lib/ansible/modules/cloud/amazon/elb_classic_lb.py
+++ b/lib/ansible/modules/cloud/amazon/elb_classic_lb.py
@@ -1063,7 +1063,10 @@ def select_stickiness_policy(self):
                     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
+                    try:
+                        expiration = self.stickiness['expiration'] if int(self.stickiness['expiration']) else None
+                    except ValueError:
+                        self.module.fail_json(msg='expiration must be set to an integer')
 
                     policy_attrs = {
                         'type': policy_type,


Test patch: