AWS Ansible

147 views
Skip to first unread message

Suporter

unread,
Jun 29, 2017, 1:58:59 AM6/29/17
to Ansible Project
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?

Suporter

unread,
Jul 3, 2017, 1:28:33 AM7/3/17
to Ansible Project
Any help?

Darragh Grealish

unread,
Jul 3, 2017, 4:58:29 AM7/3/17
to Ansible Project
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.

Suporter

unread,
Jul 4, 2017, 3:32:39 AM7/4/17
to Ansible Project
Is there a way to store all accounts keys as some files and call them as extra vars in playbook?

Dick Davies

unread,
Jul 4, 2017, 3:45:26 AM7/4/17
to ansible list
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
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5edfad13-4420-4826-a70e-5bfbd56cec86%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Suporter

unread,
Jul 4, 2017, 4:07:13 AM7/4/17
to Ansible Project
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?


On Thursday, June 29, 2017 at 11:28:59 AM UTC+5:30, Suporter wrote:

Dick Davies

unread,
Jul 4, 2017, 6:23:38 AM7/4/17
to ansible list
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/387b9c74-48a7-403d-b1b9-651c81b2312e%40googlegroups.com.

Suporter

unread,
Jul 4, 2017, 6:33:39 AM7/4/17
to Ansible Project, di...@hellooperator.net
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?

Dick Davies

unread,
Jul 4, 2017, 6:51:25 AM7/4/17
to Suporter, Ansible Project
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

Suporter

unread,
Jul 7, 2017, 3:06:26 AM7/7/17
to Ansible Project, groupf...@gmail.com, di...@hellooperator.net
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?
Reply all
Reply to author
Forward
0 new messages