I’ve been working to manage dynamic inventory in AWS for Ansible deploys… then I came across this stack overflow link & ches’ answer.
Ansible looks for executables and flat files in a directory and merges their results.
=> tree inventory/staging
-- group_vars -> ../group_vars
The base file looks like:
=> more inventory/staging/base
# I need to tell Ansible which Python on my system has boto for AWS
# The EC2 plugin will populate these groups, but we need to add empty entries
# here to make aliases for them below.
You then just point to the directory for inventory:
$ ansible -i inventory/staging webservers -m ec2_facts
$ export ANSIBLE_HOSTS=inventory/staging
$ ansible webservers -m ec2_facts
With AWS ssh, you need to use a private key. When working on a new script, I didn’t want to deal with my private account having a “build box” which was already on the VPC. So I was using my box & giving the destination a public IP. I know… totally insecure but considering I was killing the VM every few minutes I didn’t care.
So to call ansible-playbook & provide a private key:
ansible-playbook -i envs/localhost elasticsearch.yml -vvvv --private-key=~/.ssh/mykeyname.pem
I’ve got a home account & a work account. I need to easily swap between the 2.
Add 2 sets of creds
Add 2 sets of region / outputs
Then to use a profile:
aws ec2 describe-instances --profile work