# Ansible Playbook AWS

**URL:** <https://forum.ansible.com/t/ansible-playbook-aws/22089>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 22, 2016, 1:35pm UTC](https://forum.ansible.com/t/ansible-playbook-aws/22089 "2016-07-22T13:35:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amedix](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Amedix](https://forum.ansible.com/u/Amedix)\
**Post date:** [July 22, 2016, 1:35pm UTC](https://forum.ansible.com/t/ansible-playbook-aws/22089/1 "2016-07-22T13:35:22Z")

</div>

Hi,

I am new to ansible playbbok and I am trying to create AWS EC2 instance using a playbook based in some examples found in internet.

But when I run the play-book I got the following error ! but I when execute a script python using boto3 it works !?

_An exception occurred during task execution. The full traceback is:_  
_Traceback (most recent call last):_  
_File “/tmp/ansible\_f0EA27/ansible\_module\_ec2.py”, line 1434, in_   
_main()_  
_File “/tmp/ansible\_f0EA27/ansible\_module\_ec2.py”, line 1424, in main_  
_…_  
_…_

_socket.timeout: timed out_

_fatal: [localhost]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_name”: “ec2”}, “module\_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible\_f0EA27/ansible\_module\_ec2.py", line 1434, in \n main()\n File "/tmp/ansible\_f0EA27/ansible\_module\_ec2.py", line 1424, in main\n (instance\_dict\_array, new\_instance\_ids, changed) = create\_instances(module, ec2, vpc)\n File "/tmp/ansible\_f0EA27/ansible\_module\_ec2.py", line 895, in create\_instances\n vpc\_id = vpc.get\_all\_subnets(subnet\_ids=[vpc\_subnet\_id])[0].vpc\_id\n File "/usr/lib/python2.7/site-packages/boto/vpc/ **init**.py", line 1138, in get\_all\_subnets\n return self.get\_list(‘DescribeSubnets’, params, [(‘item’, Subnet)])\n File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1127, in get\_list\n response = self.make\_request(action, params, path, verb)\n File "/usr/lib/python2.7/site-packages/boto/connection.py", line 1073, in make\_request\n return self.\_mexe(http\_request)\n File "/usr/lib/python2.7/site-packages/boto/connection.py", line 910, in \_mexe\n request.body, request.headers)\n File "/usr/lib64/python2.7/httplib.py", line 979, in request\n self.\_send\_request(method, url, body, headers)\n File "/usr/lib64/python2.7/httplib.py", line 1013, in \_send\_request\n self.endheaders(body)\n File "/usr/lib64/python2.7/httplib.py", line 975, in endheaders\n self.\_send\_output(message\_body)\n File "/usr/lib64/python2.7/httplib.py", line 835, in \_send\_output\n self.send(msg)\n File "/usr/lib64/python2.7/httplib.py", line 797, in send\n self.connect()\n File "/usr/lib/python2.7/site-packages/boto/https\_connection.py", line 111, in connect\n sock.connect((self.host, self.port))\n File "/usr/lib64/python2.7/socket.py", line 224, in meth\n return getattr(self.\_sock,name)(\*args)\nsocket.timeout: timed out\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE”, “parsed”: false}_

Following is the shell environment variables and my playbook, :

_AWS\_ACCESS\_KEY\_ID=AKIAxxxxxxxxxxxx_

_AWS\_SECRET\_ACCESS\_KEY=xxxxxxxxxxxxxxx_

_- hosts: localhost_  
_connection: local_  
_gather\_facts: False_

_vars:_  
_proxy\_env:_  
_https\_proxy: “[https://172.20.xx.xx:3128](https://172.20.xx.xx:3128)”_

_tasks:_  
_- name: Create EC2 instance_  
_environment: “{{proxy\_env}}”_  
_#always\_run: true_  
_ec2:_  
_key\_name: Robby_

_group\_id: sg-2f8xxx_  
_instance\_type: t2.small_  
_ec2\_region: eu-west-1_  
_image: “ami-0b23xxx”_  
_wait: true_  
_count: 1_  
_vpc\_subnet\_id: subnet-7xxxxxx_  
_count\_tag:_  
_Name: Demo_  
_instance\_tags:_  
_Name: Demo_

_volumes:_  
_- device\_name: /dev/xvdb_  
_device\_type: standard_  
_volume\_size: 10_  
_delete\_on\_termination: true_  
_register: ec2_
