Repository: ansible/ansible

Issue:
ec2_lc - placement_tenancy default value prevents creation of launch configurations with a spot price
##### ISSUE TYPE

 - Bug Report

##### COMPONENT NAME

modules/cloud/amazon/ec2_lc

##### ANSIBLE VERSION
```
ansible 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/test/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
```

##### CONFIGURATION
No output from `ansible-config dump --only-changed`
The only ANSIBLE_* variable set is ANSIBLE_VAULT_PASSWORD_FILE=/home/test/.vault


##### OS / ENVIRONMENT
Running from Arch Linux, target is AWS

##### SUMMARY
<!--- Explain the problem briefly -->

##### 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: POC
  hosts: localhost
  connection: local

  vars_files:
    - awssecrets
    
  tasks:

     - ec2_lc:
           name: ec2 launch config with spot
           image_id: ami-ca18d8b3
           instance_type: i3.large
           spot_price: 0.02
           region: eu-west-1
           state: present
```

##### EXPECTED RESULTS
The launch configuration gets created with a spot price

##### ACTUAL RESULTS
The playbook fails to run  with the message "Placement tenancy is not supported for spot instances.", 
```
$ ansible-playbook -i hosts poc.yml -vvv
ansible-playbook 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/test/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]
Using /etc/ansible/ansible.cfg as config file
Parsed /home/test/git/ansible/hosts inventory source with ini plugin

PLAYBOOK: poc.yml ***************************************************************************************************************************************
1 plays in poc.yml
Read vars_file 'awssecrets'
Read vars_file 'awssecrets'

PLAY [POC] **********************************************************************************************************************************************
Read vars_file 'awssecrets'

TASK [Gathering Facts] **********************************************************************************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: test
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757 `" && echo ansible-tmp-1507074847.68-27868486600757="` echo /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757 `" ) && sleep 0'
<localhost> PUT /tmp/tmphUK67b TO /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757/setup.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757/ /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757/setup.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757/setup.py; rm -rf "/home/test/.ansible/tmp/ansible-tmp-1507074847.68-27868486600757/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers
Read vars_file 'awssecrets'

TASK [ec2_lc] *******************************************************************************************************************************************
task path: /home/test/git/ansible/poc.yml:11
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/amazon/ec2_lc.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: test
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543 `" && echo ansible-tmp-1507074850.03-188251403327543="` echo /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543 `" ) && sleep 0'
<localhost> PUT /tmp/tmph45VEJ TO /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543/ec2_lc.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543/ /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543/ec2_lc.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543/ec2_lc.py; rm -rf "/home/test/.ansible/tmp/ansible-tmp-1507074850.03-188251403327543/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_m4w030dh/ansible_module_ec2_lc.py", line 317, in create_launch_config
    connection.create_launch_configuration(**launch_config)
  File "/usr/lib/python3.6/site-packages/botocore/client.py", line 312, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python3.6/site-packages/botocore/client.py", line 601, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateLaunchConfiguration operation: Placement tenancy is not supported for spot instances.

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "error": {
        "code": "ValidationError", 
        "message": "Placement tenancy is not supported for spot instances.", 
        "type": "Sender"
    }, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "assign_public_ip": null, 
            "associate_public_ip_address": null, 
            "aws_access_key": null, 
            "aws_secret_key": null, 
            "classic_link_vpc_id": null, 
            "classic_link_vpc_security_groups": null, 
            "ebs_optimized": false, 
            "ec2_url": null, 
            "image_id": "ami-ca18d8b3", 
            "instance_id": null, 
            "instance_monitoring": false, 
            "instance_profile_name": null, 
            "instance_type": "i3.large", 
            "kernel_id": null, 
            "key_name": null, 
            "name": "ec2 launch config with spot fail poc", 
            "placement_tenancy": "default", 
            "profile": null, 
            "ramdisk_id": null, 
            "region": "eu-west-1", 
            "security_groups": [], 
            "security_token": null, 
            "spot_price": 0.02, 
            "state": "present", 
            "user_data": null, 
            "user_data_path": null, 
            "validate_certs": true, 
            "volumes": null, 
            "vpc_id": null
        }
    }, 
    "msg": "Failed to create launch configuration", 
    "response_metadata": {
        "http_headers": {
            "connection": "close", 
            "content-length": "308", 
            "content-type": "text/xml", 
            "date": "Tue, 03 Oct 2017 23:54:10 GMT", 
            "x-amzn-requestid": "26e2fc40-a896-11e7-be78-49d83c244553"
        }, 
        "http_status_code": 400, 
        "request_id": "26e2fc40-a896-11e7-be78-49d83c244553", 
        "retry_attempts": 0
    }
}
        to retry, use: --limit @/home/test/git/ansible/poc.retry

PLAY RECAP **********************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1
```



Discussion:

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
@@ -394,7 +394,7 @@ def main():
             classic_link_vpc_security_groups=dict(type='list'),
             classic_link_vpc_id=dict(),
             vpc_id=dict(),
-            placement_tenancy=dict(default='default', choices=['default', 'dedicated'])
+            placement_tenancy=dict(choices=['default', 'dedicated'])
         )
     )
 


Test patch: