# Is it possible to created a numbered list from a with\_sequence loop?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-created-a-numbered-list-from-a-with-sequence-loop/17446>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 4, 2015, 5:54pm UTC](https://forum.ansible.com/t/is-it-possible-to-created-a-numbered-list-from-a-with-sequence-loop/17446 "2015-02-04T17:54:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug1](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@doug1](https://forum.ansible.com/u/doug1)\
**Post date:** [February 4, 2015, 5:54pm UTC](https://forum.ansible.com/t/is-it-possible-to-created-a-numbered-list-from-a-with-sequence-loop/17446/1 "2015-02-04T17:54:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [February 4, 2015, 8:36pm UTC](https://forum.ansible.com/t/is-it-possible-to-created-a-numbered-list-from-a-with-sequence-loop/17446/2 "2015-02-04T20:36:35Z")

</div>

with\_indexed\_items - [http://docs.ansible.com/playbooks\_loops.html#looping-over-a-list-with-an-index](http://docs.ansible.com/playbooks_loops.html#looping-over-a-list-with-an-index)
