Repository: ansible/ansible

Issue:
ec2_asg regression - tags can not be bool
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_asg

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Sep  1 2016, 22:14:00) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
```

##### CONFIGURATION
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = debug
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False

##### OS / ENVIRONMENT
AWS Linux

##### SUMMARY
Previous you could define bool values in the tags parameter.  For example:

```
ec2_asg:
  tags:
    Production: True
```

However, since 2.4 this now fails with a rather cryptic error:

```
fatal: [localhost-qltst]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_QKYySN/ansible_module_ec2_asg.py\", line 1353, in <module>\n    main()\n  File \"/tmp/ansible_QKYySN/ansible_module_ec2_asg.py\", line 1342, in main\n    create_changed, asg_properties = create_autoscaling_group(connection, module)\n  File \"/tmp/ansible_QKYySN/ansible_modlib.zip/ansible/module_utils/cloud.py\", line 153, in retry_func\nAttributeError: 'ParamValidationError' object has no attribute 'response'\n",
    "module_stdout": "",
    "rc": 0
}
```

The underlying cause is that the tag is cast as a bool not a string

##### STEPS TO REPRODUCE
Create an asg with a tag bool value of `True`


##### EXPECTED RESULTS
Asg is created with True tag value

##### ACTUAL RESULTS
Play fails with ParamValidation error

ec2_asg regression - tags can not be bool
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_asg

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Sep  1 2016, 22:14:00) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
```

##### CONFIGURATION
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = debug
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False

##### OS / ENVIRONMENT
AWS Linux

##### SUMMARY
Previous you could define bool values in the tags parameter.  For example:

```
ec2_asg:
  tags:
    Production: True
```

However, since 2.4 this now fails with a rather cryptic error:

```
fatal: [localhost-qltst]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_QKYySN/ansible_module_ec2_asg.py\", line 1353, in <module>\n    main()\n  File \"/tmp/ansible_QKYySN/ansible_module_ec2_asg.py\", line 1342, in main\n    create_changed, asg_properties = create_autoscaling_group(connection, module)\n  File \"/tmp/ansible_QKYySN/ansible_modlib.zip/ansible/module_utils/cloud.py\", line 153, in retry_func\nAttributeError: 'ParamValidationError' object has no attribute 'response'\n",
    "module_stdout": "",
    "rc": 0
}
```

The underlying cause is that the tag is cast as a bool not a string

##### STEPS TO REPRODUCE
Create an asg with a tag bool value of `True`


##### EXPECTED RESULTS
Asg is created with True tag value

##### ACTUAL RESULTS
Play fails with ParamValidation error



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg.py b/lib/ansible/modules/cloud/amazon/ec2_asg.py
--- a/lib/ansible/modules/cloud/amazon/ec2_asg.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_asg.py
@@ -378,6 +378,7 @@
 import logging as log
 import traceback
 
+from ansible.module_utils._text import to_native
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, HAS_BOTO3, camel_dict_to_snake_dict, get_aws_connection_info, AWSRetry
 
@@ -794,7 +795,7 @@ def create_autoscaling_group(connection, module):
         for k, v in tag.items():
             if k != 'propagate_at_launch':
                 asg_tags.append(dict(Key=k,
-                                     Value=v,
+                                     Value=to_native(v),
                                      PropagateAtLaunch=bool(tag.get('propagate_at_launch', True)),
                                      ResourceType='auto-scaling-group',
                                      ResourceId=group_name))


Test patch: