I'm sure this must've come up before but I couldn't find an answer.

I have a list of hosts in a group.  I want to write an index number on each 
of those hosts in a file.  E.g. the first host has a file that contains 1, 
the second host has a file that contains 2 etc.

Now I know I can access the hosts using the groups variable E.g. 
groups["mygroup"] but i can't find any reference to an index so the host 
can find out which number it is.

Example play

...

- name: Add instance to new host group

  add_host:

    name: "{{ item }}"

    group: zk

  with_items:

    - server1

    - server2

    - server3


- name: deploy to zk group

  hosts: zk

  tasks:

    - name: write a myid file based on the position in the group

      copy: 

        content: {{ some_magic_variable?????? }}

        dest: /zookeeper-data/myid



In the above server i would expect to end up with three servers each with a 
myid file that contains 0, 1 or 2


Anyone know if that magic variable exists?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c3dec262-b1b5-414f-88ba-c326d4ccd93e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to