Inventory updates not appearing after provisioning ec2 instance

Hi,

After provisioning a machine on ec2 module, the inventory doesn’t reflect the new host (using ec2.py).

I am using a tag_name for the target host that comes from the inventory.

I have tried all of the following:

  • pause of 60 seconds after provisioning.

  • local_action to refresh the cache, calling ec2.py --refresh-cache

  • changing the cache_max_age timeout to 0 in ec2.ini

The other thing I tried was to use not use the inventory script, but to use add_host with the same group name as my tag name. This seems hacky though and seems also not read the group_vars, which is a problem.

If anyone has any ideas, that would be great.

Thanks,

Steve

Having a look at the inventory file immediately after the machine is provisioned, it does in fact update correctly.

However it appears that the inventory file is run/read only once at the beginning of a playbook, so it will not reflect the new host if the deploy playbook is run by including it after the provisioning playbook.

Looks like I will need to use add_host then, or find a way to get Ansible to refresh the inventory in the middle of a play.

add_host is the correct approach.

Correct - inventory files are not re-consulted in the middle of a playbook run.

Thanks Michael and and Matt.

I have noticed that the group_vars for a group added in add_host are (seemingly) not picked up. Is this correct behaviour?

If you added it to a group they should be picked up.

If seeing this in Ansible 1.7, please do file a bug.

If you need a workaround, you could:

  • include_vars: group_vars_path/groupname_here

At the top of play that targets groupname, but that should not be needed.