I'm attempting to create a playbook for zookeeper. The playbook is designed 
as a part of a role which is deployed after an AWS provisioning takes 
place. Due to the configuration of zookeeper, each host requires a 
zookeeper id (myid). This id is unique to each host in your cluster and 
must be applied before starting the service and for configuring the config 
file of zookeeper. I've seen some previous examples using a host_var that 
is configured in the inventory file for the zookeeper group, however, this 
will not work correctly with my implementation because I am using AWS to 
provision the hosts. My plan was to create a numbered list [1,2,3] for the 
length of the group list, and then use with_together to loop through and 
assign the ids to each host. See below for an example.

- debug:
    msg: "My host is {{ item.0 }} and my id is {{ item.1 }}"
  run_once: true
  with_together:
    - "{{ groups['newec2hosts'] }}"
    - [1,2,3]

The example above works fine since the list of numbers is provided, 
however, I'd like to keep this dynamic so I don't need to be constantly 
changing the list of ids when I want to add a host to the cluster. The more 
optimal solution is something like the following

- set_fact:
    zid_test: "{{ item }}"
  with_sequence: "count={{ groups['newec2hosts'] | length }}"

- debug:
    msg: "Test: {{ item.0 }} and id {{ item.1 }}"
  run_once: true
  with_together:
    - "{{ groups['newec2hosts'] }}"
    - "{{ zid_test }}"

That doesn't work since the fact is only set to the total length of the 
group list (3) and not in the order list [1,2,3]

Is there a way to accomplish this? Or perhaps another way of assigning the 
ids dynamically to each host? 






-- 
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/1509f2b1-8e74-41d4-854f-c46f012e2812%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to