# AWS Ansible

**URL:** <https://forum.ansible.com/t/aws-ansible/24846>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 29, 2017, 5:58am UTC](https://forum.ansible.com/t/aws-ansible/24846 "2017-06-29T05:58:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [June 29, 2017, 5:58am UTC](https://forum.ansible.com/t/aws-ansible/24846/1 "2017-06-29T05:58:59Z")

</div>

Hi Ansiblers,  
How can i use same playbook for multiple aws accounts, can i give the access key and secret key as command line paramters in playbook?

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [July 3, 2017, 5:28am UTC](https://forum.ansible.com/t/aws-ansible/24846/2 "2017-07-03T05:28:33Z")

</div>

Any help?

---

<div class="post-metadata">

**Author:** ![Darragh\_Grealish](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@Darragh\_Grealish](https://forum.ansible.com/u/Darragh_Grealish)\
**Post date:** [July 3, 2017, 8:58am UTC](https://forum.ansible.com/t/aws-ansible/24846/3 "2017-07-03T08:58:29Z")

</div>

Yes, you pass them as extra-vars, but there are many ways to do this, just watch out where you run your playbook and if AWS ENV variables are already set, as boto will take this into account also.  
best to understand better the AWS credentials and profiles

[http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default](http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default)

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [July 4, 2017, 7:32am UTC](https://forum.ansible.com/t/aws-ansible/24846/4 "2017-07-04T07:32:39Z")

</div>

Is there a way to store all accounts keys as some files and call them as extra vars in playbook?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [July 4, 2017, 7:45am UTC](https://forum.ansible.com/t/aws-ansible/24846/5 "2017-07-04T07:45:15Z")

</div>

Yes, you can use lookups, like this

- name: set authorized\_keys  
authorized\_key: user={{ item }} exclusive=yes  
key="{{ lookup('file', 'files/pubkeys/{{ item }}.key') }}"  
with\_items: "{{ team\_members[team] }}"

team\_members[team] here is a list of usernames,  
the files live in rolename/files/pubkeys/$username.key

original role is here :  
[https://github.com/rasputnik/ansible-sshteams/blob/master/roles/teams/tasks/team.yml](https://github.com/rasputnik/ansible-sshteams/blob/master/roles/teams/tasks/team.yml)

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [July 4, 2017, 8:07am UTC](https://forum.ansible.com/t/aws-ansible/24846/6 "2017-07-04T08:07:13Z")

</div>

Oh my god, my head is spinning. I have 3 accounts in AWS, i need to create a file for each account? and then i need to give that name in playbook?

i am expecting something like this

ansible-playbook newmachine.yml --extra-vars “account=myaccount” and i want the new ec2 instance to be spinned up in that account. how can i do this?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [July 4, 2017, 10:23am UTC](https://forum.ansible.com/t/aws-ansible/24846/7 "2017-07-04T10:23:25Z")

</div>

Sorry I thought you wanted to know about file lookups (in this case  
it's ssh keys).

If the -e 'credentials=/path/to/credentials' , you just need to lookup  
the file and  
read it's contents. Or just set environment variables before you run  
the playbook, I  
thought the aws related modules read the environment fine.

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [July 4, 2017, 10:33am UTC](https://forum.ansible.com/t/aws-ansible/24846/8 "2017-07-04T10:33:39Z")

</div>

Sorry, i dont really know where to start,  
Should i save the keys in some file and refer that fiile in the playbook as a variable?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [July 4, 2017, 10:51am UTC](https://forum.ansible.com/t/aws-ansible/24846/9 "2017-07-04T10:51:13Z")

</div>

No, just keep it simple and set the environment variables; then you  
can't accidentally  
commit credentials to a repo or use the wrong account.

[http://docs.ansible.com/ansible/guide\_aws.html](http://docs.ansible.com/ansible/guide_aws.html)

---

<div class="post-metadata">

**Author:** ![groupfiles14](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@groupfiles14](https://forum.ansible.com/u/groupfiles14)\
**Post date:** [July 7, 2017, 7:06am UTC](https://forum.ansible.com/t/aws-ansible/24846/10 "2017-07-07T07:06:26Z")

</div>

i am new to ansible and i am struggling a bit here ☹ how can i save multiple accounts credentials in ansible server and call them in command line?
