Repository: ansible/ansible

Issue:
ec2_lc ignores instance_monitoring setting

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_lc 

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.1.0
  config file = /Users/dmt/Code/infrastructure/ansible.cfg
  configured module search path = [u'/Users/dmt/.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.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
NA

##### SUMMARY
<!--- Explain the problem briefly -->
Creating a new launch configuration always has Monitoring set to enabled

Possible cause (instance_monitoring being false never setting the value):
https://github.com/ansible/ansible/blob/3a6fad38fa5003222f864d583dadf23700aa3ebe/lib/ansible/modules/cloud/amazon/ec2_lc.py#L310-L311


##### 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
  ec2_lc:
    image_id: ami-123
    key_name: "{{ aws_dev_keypair_name }}"
    instance_monitoring: "false"

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
A launch configuration with monitoring disabled

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
A launch configuration with monitoring enabled

<!--- Paste verbatim command output between quotes below -->
(Truncated output of -vvvv relevant to this:)
```
changed: [localhost] => {
    "changed": true,
    "failed": false,
    "invocation": {
        "module_args": {
            "instance_monitoring": false,
        }
    },
    "result": {
        "instance_monitoring": true,
    }
}
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/ec2_lc.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/ec2_lc.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 @garethr @willthames @wilvk
[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/ec2_lc.py b/lib/ansible/modules/cloud/amazon/ec2_lc.py
--- a/lib/ansible/modules/cloud/amazon/ec2_lc.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_lc.py
@@ -307,7 +307,7 @@ def create_launch_config(connection, module):
     if classic_link_vpc_id is not None:
         launch_config['ClassicLinkVPCId'] = classic_link_vpc_id
 
-    if instance_monitoring:
+    if instance_monitoring is not None:
         launch_config['InstanceMonitoring'] = {'Enabled': instance_monitoring}
 
     if classic_link_vpc_security_groups is not None:


Test patch: