Repository: ansible/ansible

Issue:
In elb_target_group_module specifying wait without specifying wait_timeout raise TypeError
##### SUMMARY
Same as title. Also, the [document](https://docs.ansible.com/ansible/2.5/modules/elb_target_group_module.html) for that module does not list the `wait` and `wait_timeout` in the module properties!

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
elb_target_group_module

##### ANSIBLE VERSION
```
ansible 2.6.0
  config file = None
  configured module search path = ['/Users/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/redacted/.local/share/virtualenvs/deployment-urGlj6Al/lib/python3.6/site-packages/ansible
  executable location = /Users/redacted/.local/share/virtualenvs/deployment-urGlj6Al/bin/ansible
  python version = 3.6.5 (default, Apr 12 2018, 13:43:59) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create or update target group for Load Balancer
  elb_target_group:
    region: 'some_region'
    vpc_id: 'vpc_id'
    name: 'some_name' 
    protocol: http
    port: 80
    state: present
    health_check_protocol: http
    health_check_port: 80
    health_check_path: '/'
    health_check_timeout: 10
    health_check_interval: 30
    healthy_threshold_count: 2
    modify_targets: yes
    wait: yes
    targets:
      - Id: 'instance_id'
        Port: 80
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
No error displayed by using a default value for `wait_timeout`

##### ACTUAL RESULTS
```
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 705, in <module>
    main()
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 699, in main
    create_or_update_target_group(connection, module)
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 579, in create_or_update_target_group
    status_achieved, registered_instances = wait_for_status(connection, module, tg['TargetGroupArn'], params['Targets'], 'healthy')
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 349, in wait_for_status
    max_retries = (module.params.get('wait_timeout') // polling_increment_secs)
TypeError: unsupported operand type(s) for //: 'NoneType' and 'int'
```

In elb_target_group_module specifying wait without specifying wait_timeout raise TypeError
##### SUMMARY
Same as title. Also, the [document](https://docs.ansible.com/ansible/2.5/modules/elb_target_group_module.html) for that module does not list the `wait` and `wait_timeout` in the module properties!

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
elb_target_group_module

##### ANSIBLE VERSION
```
ansible 2.6.0
  config file = None
  configured module search path = ['/Users/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/redacted/.local/share/virtualenvs/deployment-urGlj6Al/lib/python3.6/site-packages/ansible
  executable location = /Users/redacted/.local/share/virtualenvs/deployment-urGlj6Al/bin/ansible
  python version = 3.6.5 (default, Apr 12 2018, 13:43:59) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create or update target group for Load Balancer
  elb_target_group:
    region: 'some_region'
    vpc_id: 'vpc_id'
    name: 'some_name' 
    protocol: http
    port: 80
    state: present
    health_check_protocol: http
    health_check_port: 80
    health_check_path: '/'
    health_check_timeout: 10
    health_check_interval: 30
    healthy_threshold_count: 2
    modify_targets: yes
    wait: yes
    targets:
      - Id: 'instance_id'
        Port: 80
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
No error displayed by using a default value for `wait_timeout`

##### ACTUAL RESULTS
```
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 705, in <module>
    main()
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 699, in main
    create_or_update_target_group(connection, module)
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 579, in create_or_update_target_group
    status_achieved, registered_instances = wait_for_status(connection, module, tg['TargetGroupArn'], params['Targets'], 'healthy')
  File "/var/folders/pt/scv7gx297rg5ns2nt1f2w90r0000gn/T/ansible_5ak5igpc/ansible_module_elb_target_group.py", line 349, in wait_for_status
    max_retries = (module.params.get('wait_timeout') // polling_increment_secs)
TypeError: unsupported operand type(s) for //: 'NoneType' and 'int'
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/elb_target_group.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/elb_target_group.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 --->
Even when I specify both `wait` and `wait_timout` the module fails with a vague error:

```
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "aws_access_key": null,
            "aws_secret_key": null,
            "deregistration_delay_timeout": null,
            "ec2_url": null,
            "health_check_interval": 30,
            "health_check_path": "/",
            "health_check_port": "80",
            "health_check_protocol": "http",
            "health_check_timeout": 10,
            "healthy_threshold_count": 2,
            "modify_targets": true,
            "name": "some_name",
            "port": 80,
            "profile": null,
            "protocol": "http",
            "purge_tags": true,
            "region": "ap-southeast-2",
            "security_token": null,
            "state": "present",
            "stickiness_enabled": null,
            "stickiness_lb_cookie_duration": null,
            "stickiness_type": "lb_cookie",
            "successful_response_codes": null,
            "tags": {},
            "target_type": "instance",
            "targets": [
                {
                    "Id": "instance_id",
                    "Port": 80
                }
            ],
            "unhealthy_threshold_count": null,
            "validate_certs": true,
            "vpc_id": "vpc_id",
            "wait": true,
            "wait_timeout": 30
        }
    },
    "msg": "Error waiting for target registration - please check the AWS console"
}
```
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/elb_target_group.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/elb_target_group.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 --->
Even when I specify both `wait` and `wait_timout` the module fails with a vague error:

```
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "aws_access_key": null,
            "aws_secret_key": null,
            "deregistration_delay_timeout": null,
            "ec2_url": null,
            "health_check_interval": 30,
            "health_check_path": "/",
            "health_check_port": "80",
            "health_check_protocol": "http",
            "health_check_timeout": 10,
            "healthy_threshold_count": 2,
            "modify_targets": true,
            "name": "some_name",
            "port": 80,
            "profile": null,
            "protocol": "http",
            "purge_tags": true,
            "region": "ap-southeast-2",
            "security_token": null,
            "state": "present",
            "stickiness_enabled": null,
            "stickiness_lb_cookie_duration": null,
            "stickiness_type": "lb_cookie",
            "successful_response_codes": null,
            "tags": {},
            "target_type": "instance",
            "targets": [
                {
                    "Id": "instance_id",
                    "Port": 80
                }
            ],
            "unhealthy_threshold_count": null,
            "validate_certs": true,
            "vpc_id": "vpc_id",
            "wait": true,
            "wait_timeout": 30
        }
    },
    "msg": "Error waiting for target registration - please check the AWS console"
}
```

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/elb_target_group.py b/lib/ansible/modules/cloud/amazon/elb_target_group.py
--- a/lib/ansible/modules/cloud/amazon/elb_target_group.py
+++ b/lib/ansible/modules/cloud/amazon/elb_target_group.py
@@ -130,6 +130,17 @@
     description:
       - The identifier of the virtual private cloud (VPC). Required when I(state) is C(present).
     required: false
+  wait:
+    description:
+      - Whether or not to wait for the target group.
+    type: bool
+    default: false
+    version_added: "2.4"
+  wait_timeout:
+    description:
+      - The time to wait for the target group.
+    default: 200
+    version_added: "2.4"
 extends_documentation_fragment:
     - aws
     - ec2
@@ -515,7 +526,7 @@ def create_or_update_target_group(connection, module):
                     if module.params.get("wait"):
                         status_achieved, registered_instances = wait_for_status(connection, module, tg['TargetGroupArn'], instances_to_add, 'healthy')
                         if not status_achieved:
-                            module.fail_json(msg='Error waiting for target registration - please check the AWS console')
+                            module.fail_json(msg='Error waiting for target registration to be healthy - please check the AWS console')
 
                 remove_instances = set(current_instance_ids) - set(new_instance_ids)
 
@@ -578,7 +589,7 @@ def create_or_update_target_group(connection, module):
             if module.params.get("wait"):
                 status_achieved, registered_instances = wait_for_status(connection, module, tg['TargetGroupArn'], params['Targets'], 'healthy')
                 if not status_achieved:
-                    module.fail_json(msg='Error waiting for target registration - please check the AWS console')
+                    module.fail_json(msg='Error waiting for target registration to be healthy - please check the AWS console')
 
     # Now set target group attributes
     update_attributes = []
@@ -685,8 +696,8 @@ def main():
             targets=dict(type='list'),
             unhealthy_threshold_count=dict(type='int'),
             vpc_id=dict(),
-            wait_timeout=dict(type='int'),
-            wait=dict(type='bool')
+            wait_timeout=dict(type='int', default=200),
+            wait=dict(type='bool', default=False)
         )
     )
 


Test patch:
diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt
--- a/test/sanity/validate-modules/ignore.txt
+++ b/test/sanity/validate-modules/ignore.txt
@@ -96,7 +96,6 @@ lib/ansible/modules/cloud/amazon/elb_application_lb.py E324
 lib/ansible/modules/cloud/amazon/elb_classic_lb_facts.py E323
 lib/ansible/modules/cloud/amazon/elb_instance.py E326
 lib/ansible/modules/cloud/amazon/elb_target.py E327
-lib/ansible/modules/cloud/amazon/elb_target_group.py E322
 lib/ansible/modules/cloud/amazon/elb_target_group.py E324
 lib/ansible/modules/cloud/amazon/elb_target_group.py E325
 lib/ansible/modules/cloud/amazon/elb_target_group.py E326