# Templates, loops, dynamically list 1 or more lines

**URL:** <https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598>\
**Category:** Ansible Project\
**Created:** [July 3, 2014, 11:46am UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598 "2014-07-03T11:46:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [July 3, 2014, 11:46am UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598/1 "2014-07-03T11:46:26Z")

</div>

I have to write a template so that I can produce the following - queue physicalName can vary in quantity, and may have 1 2 or 3 entries typically. This seems to be the challenge. I can do a more static version with - { ‘x’:‘y’, ‘z’:‘a’ } but then I can’t figure out how to dynamically list more than 1 entry for physicalName without affecting every line in my output - I have 30 queues to set up like this.

I’m at loss how to do this. I could paste numerous examples of what I’ve done, but I feel it’s a tad pointless as I feel I’m so far away from having something remotely credible. Sorry!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 3, 2014, 1:46pm UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598/2 "2014-07-03T13:46:45Z")

</div>

Jinja2 questions should be pretty easy, though to understand better, what are the variable inputs coming into the template?

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [July 3, 2014, 1:57pm UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598/3 "2014-07-03T13:57:06Z")

</div>

I’m frequently finding myself at lost in jinja2. Petros example worked ( i can’t see it here!?!) , and I’m back on track - thanks!

The composite queues are fuse mq queues our infrastructure can subscribe to. Physical queues forward copies of messages, logstash or mule for example.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 3, 2014, 7:59pm UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598/4 "2014-07-03T19:59:52Z")

</div>

Without some examples of what the variables are I’m afraid I can’t provide further help.

The looping and such is pretty straightforward so it would be easy to offer examples.

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [July 3, 2014, 8:07pm UTC](https://forum.ansible.com/t/templates-loops-dynamically-list-1-or-more-lines/15598/5 "2014-07-03T20:07:21Z")

</div>

It seems the response I’m referring to is not on the thread - here it is:

"You can define your data like this:

`queues:`  
`logstash:`  
`name: 1P.LOGSTASH`  
`something:`  
`name: 1P.SOMETHING`  
`foo:`  
`name: 1P.FOO`  
`bar:`  
`name: 1P.BAR`

`composite_queues:`  
`- name: 1P.EMAIL`  
`queues:`  
`- logstash`  
`- name: 1P.IP_EVT`  
`queues:`  
`- logstash`  
`- something`  
`- name: 1P.IP_BLAH`  
`queues:`  
`- logstash`  
`- foo`  
`- bar`

Then your template would look like this:

`{% for composite_queue in composite_queues %}`  
`<compositeQueue name="{{ [composite_queue.name](http://composite_queue.name/) }}" forwardOnly="false">`  
`<forwardTo>`  
`{% for queue in composite_queue.queues %}`  
```` `{% endfor %}` `` `` `{% endfor %}`
