In boto, get_all_groups has a max return of 100. to get past that, you use tokens:
asconn = boto.ec2.autoscale.connect_to_region(self.region_name)
# This will load all groups.
# Source: http://stackoverflow.com/questions/29317526/how-can-i-retrieve-more-than-50-autoscaling-groups-via-python-boto
all_groups = 
rs = asconn.get_all_groups()
rs = asconn.get_all_groups(next_token=rs.next_token)
for asg in all_groups:
print self.stack_name + " = " + asg.name
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
If you haven’t done so already, configure the EC2 CLI tools. You can download the latest EC2 toolchain from here.
(It’s also available using homebrew “brew install ec2-api-tools”)
Now configure the environment variables:
Note: The Java path cannot be a symlink. It must be the actual path to the java home.
Test the EC2 CLI tools by running: