# Add asnsible\_host for each member of a group.

**URL:** <https://forum.ansible.com/t/add-asnsible-host-for-each-member-of-a-group/25975>\
**Category:** Ansible Project\
**Created:** [November 9, 2017, 11:19am UTC](https://forum.ansible.com/t/add-asnsible-host-for-each-member-of-a-group/25975 "2017-11-09T11:19:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Olivieri](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@Federico\_Olivieri](https://forum.ansible.com/u/Federico_Olivieri)\
**Post date:** [November 9, 2017, 11:19am UTC](https://forum.ansible.com/t/add-asnsible-host-for-each-member-of-a-group/25975/1 "2017-11-09T11:19:27Z")

</div>

Hi all

I have a group like this:

```auto
[webservers]
www[01:50].example.com

I would like to understand if there is a way to assign ansible_host variable for each member of the group like:

www01.example.com ansible_host=1.1.1.1
www02.example.com ansible_host=1.1.1.2
www03.example.com ansible_host=1.1.1.3

Obviously I would like to do it in one line, without define variable for each host like using regex

[webservers]
www[01:50].example.com ansible_host=1.1.1.[1:50]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 9, 2017, 3:15pm UTC](https://forum.ansible.com/t/add-asnsible-host-for-each-member-of-a-group/25975/2 "2017-11-09T15:15:29Z")

</div>

No, hostvars do not support ranges, but you can define a single  
hostvar for the range and use templating to get what you want.

www[01:50].example.com ansible\_host={{'1.1.1.' +  
inventory\_hostname.split('.')[0]|regex\_replace('www','') }}

^ have not tested it, but something like this should work.
