I\'m using Ansible to setup EC2 instances and deploy an app. There\'s a hosts script which gathers tags related servers and groups info. I\'d like to run these actions as a
You can also edit the ec2.ini file and set the option:
cache_max_age = 0
to prevent the need for reload by making sure that nothing is cached in the first place.
I found the meta: refresh_inventory
to be insufficient.
I had to add an explicit call to ec2.py --refresh-cache
first.
- name: refresh inventory hosts: localhost connection: local gather_facts: False tasks: - name: Refresh EC2 cache command: /etc/ansible/ec2.py --refresh-cache - name: Refresh in-memory EC2 cache meta: refresh_inventory
Take a look at add_host.
It does add a host (and alternatively a group) to the ansible-playbook in-memory inventory
With Ansible 2.0+, you can refresh your inventory mid-play by running the task:
- meta: refresh_inventory
Ansible currently doesn't support this. If you look at the source code of the ansible
or ansible-playbook
commands you'll see that the inventory is loaded first and then the inventory object is passed to the ansible command that runs the specified task or playbook. Moving the inventory processing so that it happens within the task/playbook handlers would probably be a pretty major undertaking for a number of reasons.
Your best bet when doing something like this is to simply break your playbook into two and wrap their calls in a shell script that you only have to invoke once.