ansible and cloud instances
A few days ago I posted about using ansible to provision persistent ip instances in a public or private cloud.
Today I finished up the next piece I needed to make this work for copr builders w/transient ips/instances.
I needed a way to create a new instance, provision it as if it was one of the normal inventory of our systems, and return back the ip of that was given to it via eucalyptus (or ec2) automatically. And when I was done with it – I didn’t want any record of it preserved in our inventory system. I wanted it gone.
The problem was ansible wants to act only on the hosts it knows about in its inventory. This is quite understandable. But since I’m not specifying an ip to this host and I don’t know it in advance I wanted a way, in a single playbook to do this.
So I wrote add_host an action_plugin for ansible. These let you interact with the internal state of the inventory/playbook/etc while executing a playbook.
All it does is to add the host to the in-memory inventory the ansible playbook object has. And it adds that host to a group you specify. This is so in the second play in the playbook you can say ‘oh operate on hosts in this special group name’ and that will be the only host in that group.
I’ve sent in a pull request for it but it’s not been accepted quite yet. However, if you want to try it out you can just toss it into your action_plugins dir in ansible and call it.
Here’s an example playbook. It’s very similar to the one for creating a persistent instance. In the fedora public ansible repo we are, in fact, importing the same set of tasks from another file to set them up the same.
It just means if anyone wants an instance in our private cloud running f17 or el6 it is incredibly trivial to make one available for you.