# Generating a sequence number

**URL:** <https://forum.ansible.com/t/generating-a-sequence-number/18216>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [May 12, 2015, 9:00pm UTC](https://forum.ansible.com/t/generating-a-sequence-number/18216 "2015-05-12T21:00:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theodore](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Theodore](https://forum.ansible.com/u/Theodore)\
**Post date:** [May 12, 2015, 9:00pm UTC](https://forum.ansible.com/t/generating-a-sequence-number/18216/1 "2015-05-12T21:00:48Z")

</div>

I need to generate hostnames for a concurrent service that contain sequences. So I create 5 AWS instances and I want to call them h001, h002, h003, h004, h005.

I create the instances concurrently and then use dynamic inventory to drive subsequent plays. How do I implement a sequence number in Ansible so that I can name these hosts in this way?

---

<div class="post-metadata">

**Author:** ![Evan\_Meagher](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@Evan\_Meagher](https://forum.ansible.com/u/Evan_Meagher)\
**Post date:** [May 12, 2015, 11:29pm UTC](https://forum.ansible.com/t/generating-a-sequence-number/18216/2 "2015-05-12T23:29:38Z")

</div>

You could use a `[local_action](http://docs.ansible.com/playbooks_delegation.html)` to shell out to some command that generates IDs [1]. This technique is often used to generate passwords in Ansible plays [2,3]. You could generate hostnames in the same way by simply restricting the alphabet of generated strings to something like `[0-9]{3}`.

[1] [https://groups.google.com/forum/#!topic/ansible-project/xthTljaVeEI](https://groups.google.com/forum/#!topic/ansible-project/xthTljaVeEI)

[2] [https://groups.google.com/forum/#!topic/ansible-project/8zLKXnwCF9s](https://groups.google.com/forum/#!topic/ansible-project/8zLKXnwCF9s)

[3] [https://gist.github.com/eosrei/5191334](https://gist.github.com/eosrei/5191334)
