How to best use Ansible in an autoscaling environment?

Hi all,

So I’ve been thinking about how to best use Ansible in an autoscaling environment on AWS, and I was wondering if anyone else had dealt with this, and if they had any advice.

My thought is to essentially do some kind of push/pull hybrid. Something like:

  • When a new instance comes online, have it pull an artifact (gz file, zip, etc.) from a known place on S3 - something like s3://bucket/latest.tar.gz. Unzip it into a known location, and run whatever commands to get it online.
  • When we’re pushing a new version of the code out, update the latest artifact on the bucket, and from a central server, use the AWS module to find all instances with the same Name, and issue a command to force them to grab the latest copy and install.
  • The code would have some kind of playbook embedded in it, so after the latest copy is pulled down, that playbook just gets run.

In this way, we’re not refreshing the code every n minutes via cron, and things stay more steady; the instances only update when they have to. I suppose another alternative is to have the instances access a Git repository and pull down the code from there, but then you have to deal with private repos.

Has anyone done anything like this?

Hello,

I’ve done a lot of demos of this sort of thing using Ansible Tower’s ‘callbacks’ feature. A playbook is exposed as a URL - embed a call to that URL[1] in user-data when spinning up an instance, and you have a ‘phone home’ solution that keeps the beauty of the push model.

–Mark

[1] Here’s an example of that exact user-data https://github.com/phips/tiad_demo/blob/master/scripts/ec2_bootstrap.sh

** Full disclosure and all that - I work for Ansible.

Thanks for the reply! That’s the sort of solution I was looking for.

  • greg