Hello everyone!
I've been racking my brains for the past few weeks to imitate a behavior
I've sub-optimally accomplished with Chef, using Ansible.Here is what I do today, directly from my Chef server:
whenever I provision / decommission machines in amazon (through chef, but
how they are provisioned is irrelevant)
the script that does said job, adds them to the chef hosts database (after
enrolling them)
later on, Chef runs a recipe on all machines, that queries the hosts
database and creates an /etc/hosts file with all known machinesThis is all automated -- step #3 above happens every 30 minutes.
Now, I've wanted to make this event-based so the recipe is run every time a
machine is provisioned in amazon, which, in the Chef world, would require me
to run chef-client --once on every machine, every time the machine inventory
is modified. This requires me to run the WHOLE of the chef execution across
the WHOLE network. This is suboptimal, of course.How do I go about replicating this setup with Ansible?
Replicating the suboptimal case?
I understand I have to write a playbook with a play that generates
/etc/hosts from the inventory, and then pushes it to every machine in my
ansible inventory. How do I do that?
You should just use the template module and do something like...
{% for host in groups['all'] %}
host {% hostvars[host]["ansible_hostname"] %}
{% endfor %}
in the template, and then, just have a play like this:
- hosts: all
tasks:
- template: src=/some/path/hosts.j2 dest=/etc/hosts
What best practices exist or do you know, to coordinate a play execution
upon an event happening, such as "machine added to Amazon / static
inventory"?
This doesn't really exist.