Reputation: 41823
I have a list of three hosts in a dynamic inventory (ec2.py). I want to assign an auto-incrementing integer to a hostvar of each. For example, the first EC2 instance would get a hostvar foo=1
, the second would get foo=2
, and the third foo=3
. Does anyone have any idea how to do that? I've looked at loops and the "set_fact" module, but I can't quite figure out how to do it. Any help would be much appreciated.
Upvotes: 0
Views: 459
Reputation: 59989
I don't think this is possible with any task or construct inside Ansible playbooks, since all this pretty much does run per host and in each loop you do not know about the state of the other hosts.
I think your best bet would be to create a modified version of the ec2.py
and just increment a global var there. I never used the ec2.py
but it appears the function get_host_info_dict_from_instance()
is where the host_vars
are collected. You should be able to inject your counter var there.
Upvotes: 1