I'm using Ansible to setup EC2 instances and deploy an application. There's a hosts script which gathers tags related servers and groups info. I'd like to run these actions as a single playbook, so
- New instances are created if needed
- Hosts script loads inventory (including servers' facts)
- Deployment playbook works
However, the inventory is loaded in advance, so, there is no servers/groups data if servers are created/updated during the play. I can
- separate provision and deployment playbooks
- use add_host trick to emulate dynamic inventory when servers are updated
But, there are drawbacks in those approaches.
Can I force Ansible to reload inventory?
My test files are:
hosts
script:
#!/bin/sh
echo `date` >> log.log
echo "{\"standalone\":[\"localhost\"]}"
Sample playbook.yml
:
---
- hosts: all
tasks:
- name: show inventory_hostname
command: echo {{ inventory_hostname }}
I run it with the command ansible-playbook -i hosts playbook.yml -v
and see two runs:
$> cat log.log
Thu Mar 12 09:43:16 SAMT 2015
Thu Mar 12 09:43:16 SAMT 2015
but I haven't found a command to double it.
add_host
module? – Correyadd_host
here is duplicative. I am provisioning a number of hosts based on a list, but this breaks the "register: ec2" pattern that's common in ansible ec2 provisioning examples, because the result is a list of return values. Ideally ansible would allow me to run a two-phased provisioning process in the same playbook: 1) create a bunch of instances, then 2) address them by group and do some basic configuration (like setting up DNS, etc). – Pains