Repository: ansible/ansible

Issue:
Comparison of rule priority compares a string to an int
##### SUMMARY
In the compare_rules function in module_utils/aws/elbv2.py a comparison is made between current_rule['Priority'] and new_rule['Priority'] which evaluates to false because the current_rule['Priority'] is a string and the new_rule['Priority'] is an integer

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
elb_application_lb

##### ANSIBLE VERSION
```
ansible 2.7.0.dev0 (devel 7ba0d8f60e) last updated 2018/07/25 15:21:07 (GMT -700)
  config file = None
  configured module search path = [u'/home/mjmayer/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mjmayer/ansible/lib/ansible
  executable location = /home/mjmayer/ansible/bin/ansible
  python version = 2.7.5 (default, Jul  3 2018, 06:28:28) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28.0.1)]
```


##### STEPS TO REPRODUCE

```python
686             rules_to_add = deepcopy(self.rules)
687
688             for current_rule in self.current_rules:
689                 current_rule_passed_to_module = False
690                 for new_rule in self.rules[:]:
691  ->                 if current_rule['Priority'] == new_rule['Priority']:
692                         current_rule_passed_to_module = True
693                         # Remove what we match so that what is left can be marked as 'to be added'
694                         rules_to_add.remove(new_rule)
695                         modified_rule = self._compare_rule(current_rule, new_rule)
696                         if modified_rule:
```

##### EXPECTED RESULTS
```
(Pdb)  current_rule['Priority']
95
(Pdb) new_rule['Priority']
95
(Pdb) current_rule['Priority'] == new_rule['Priority']
True
```

##### ACTUAL RESULTS
```
(Pdb)  current_rule['Priority']
'95'
(Pdb) new_rule['Priority']
95
(Pdb) current_rule['Priority'] == new_rule['Priority']
False

```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/elb_application_lb.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/elb_application_lb.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi @mjmayer,

Thank you for the issue, just so you are aware we have a dedicated Working Group for aws.
You can find other people interested in this in #ansible-aws on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: community_workgroups --->

Resolving patch:
diff --git a/lib/ansible/module_utils/aws/elbv2.py b/lib/ansible/module_utils/aws/elbv2.py
--- a/lib/ansible/module_utils/aws/elbv2.py
+++ b/lib/ansible/module_utils/aws/elbv2.py
@@ -688,7 +688,7 @@ def compare_rules(self):
         for current_rule in self.current_rules:
             current_rule_passed_to_module = False
             for new_rule in self.rules[:]:
-                if current_rule['Priority'] == new_rule['Priority']:
+                if current_rule['Priority'] == str(new_rule['Priority']):
                     current_rule_passed_to_module = True
                     # Remove what we match so that what is left can be marked as 'to be added'
                     rules_to_add.remove(new_rule)


Test patch: