Title: AWS provision with ansible
Tags: amazon-web-services;ansible
Question: I am getting and error when I want to provision an ec2. This is how i set up my environment.
I put my aws credentials in ~/.boto
cat  /etc/ansible/hosts
[local]
localhost
cat /etc/ansible/ec2-vars/testserver.yml
ec2_keypair: "ansible"
ec2_security_group: "sg-*******"
ec2_instance_type: "t2.micro"
ec2_image: "ami-********"
ec2_subnet_ids: ['subnet-*******','subnet-REDACTED','subnet-REDACTED']
ec2_region: "us-east-1"
ec2_tag_Name: "testserver"
ec2_tag_Type: "testserver"
ec2_tag_Environment: "development"
ec2_volume_size: 8
cat /etc/ansible/provision-ec2.yml
---
- hosts: localhost
connection: local
gather_facts: false
user: root
pre_tasks:
- include_vars: ec2_vars/{{type}}.yml
roles:
- provision-ec2
cat /etc/ansible/roles/provision-ec2/tasks/main.yml
---
- name: Provision EC2 Box
local_action:
module: ec2
key_name: "{{ ec2_keypair }}"
group_id: "{{ ec2_security_group }}"
instance_type: "{{ ec2_instance_type }}"
image: "{{ ec2_image }}"
vpc_subnet_id: "{{ ec2_subnet_ids|random }}"
region: "{{ ec2_region }}"
instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"       {{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}'
assign_public_ip: yes
wait: true
count: 1
volumes:
- device_name: /dev/sda1
device_type: gp2
volume_size: "{{ ec2_volume_size }}"
delete_on_termination: true
register: ec2
- debug: var=item
with_items: ec2.instances
- add_host: name={{ item.public_ip }} &gt;
groups=tag_Type_{{ec2_tag_Type}},tag_Environment_{{ec2_tag_Environment}}
ec2_region={{ec2_region}}
ec2_tag_Name={{ec2_tag_Name}}
ec2_tag_Type={{ec2_tag_Type}}
ec2_tag_Environment={{ec2_tag_Environment}}
ec2_ip_address={{item.public_ip}}
with_items: ec2.instances
- name: Wait for the instances to boot by checking the ssh port
wait_for: host={{item.public_ip}} port=22 delay=60 timeout=320     state=started
with_items: ec2.instances
Now I run the following command and this is what i get.
[root@ip-**-**-*** ansible]# ansible-playbook -vv -i localhost, -e     "type=testservers" provision-ec2.yml
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: provision-ec2.yml   ****************************************************
1 plays in provision-ec2.yml
PLAY [localhost] ***************************************************************
TASK [include_vars] ************************************************************
task path: /etc/ansible/provision-ec2.yml:7
fatal: [localhost]: FAILED! =&gt; {"changed": false, "failed": true, "file":    "/etc/ansible/ec2_vars/testservers.yml", "msg": "Source file not found."}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @provision-ec2.retry
PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1
please help.
New error:
TASK [provision-ec2 : Provision EC2 Box] ***************************************
task path: /etc/ansible/roles/provision-ec2/tasks/main.yml:2
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials"}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @provision-ec2.retry
PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

Here is the accepted answer: You are mixing underscore and hyphen.
cat /etc/ansible/ec2-vars/testserver.yml
include_vars: ec2_vars/{{type}}.yml
Comment for this answer: `~/.boto` is the last in search hierarchy. Check you have the files listed in `http://boto.cloudhackers.com/en/latest/boto_config_tut.html` before `~/.boto`
Comment for this answer: Thanks, now I am getting a new error. I stored aws credentials in ~./boto.   I just edited the post to reflect the new error. @helloV
Comment for this answer: @tedder42 I think i fixed the .boto issue. the problem am now facing something else. I will tag you in a separate question .
Comment for this answer: @helloV I fixed the boto issue. thanx
Comment for this answer: TLDR: you're doing boto wrong. Lolu911 answered your original question, put the .boto file in a second question.
Comment for this answer: also note that with those tags you can simply put your vars at group_vars/ec2_tag_Type.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:05/23/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<amazon-web-services><ansible>', 'Title': 'AWS provision with ansible', 'ViewCount': 749, 'id': 37398034, 'user_AboutMe': None, 'user_AccountId': 3179175.0, 'user_DisplayName': 'Lolu911', 'user_Reputation': 85.0, 'user_Views': 15.0, 'user_id': 2686325.0}}