Reputation: 3876
It this possible to get current for loop counter when using ansible and iterating over hosts provided?
- name: Debug me
hosts: [1.2.3.4, 1.3.4.5]
user: root
tasks:
- debug: msg="{{ inventory_hostname }}"
- debug: msg="{{ forloop.counter }}" # ??
Any help appreciated.
Upvotes: 2
Views: 2709
Reputation: 68289
It is not actually a loop in ansible, but I think you want:
- name: Debug me
hosts: [1.2.3.4, 1.3.4.5]
user: root
tasks:
- debug: msg="{{ inventory_hostname }}"
- debug: msg="{{ play_hosts.index(inventory_hostname) }}"
Upvotes: 4