# Easier way to select host group value

**URL:** <https://forum.ansible.com/t/easier-way-to-select-host-group-value/12911>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [June 5, 2013, 6:19pm UTC](https://forum.ansible.com/t/easier-way-to-select-host-group-value/12911 "2013-06-05T18:19:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 5, 2013, 6:19pm UTC](https://forum.ansible.com/t/easier-way-to-select-host-group-value/12911/1 "2013-06-05T18:19:54Z")

</div>

Assuming this is a template, if you need more than 5, normally this would be accessed in a loop like so:

{% for x in groups[‘JournalNodes’] %}  
{{ hostvars[…] }}  
{% end for %}

You can also use {% set % } to define variables and make things shorter in templates

Let me know if I’m misunderstanding the use case.

You should be able to use python slicing in the loop (haven’t tried!) to get the first 5 nodes like:

{% for x in groups[‘JournalNodes’][0:4] %}
