# Hosts with subnets ?

**URL:** <https://forum.ansible.com/t/hosts-with-subnets/11801>\
**Category:** Ansible Project\
**Created:** [August 16, 2012, 8:05am UTC](https://forum.ansible.com/t/hosts-with-subnets/11801 "2012-08-16T08:05:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [August 16, 2012, 8:05am UTC](https://forum.ansible.com/t/hosts-with-subnets/11801/1 "2012-08-16T08:05:57Z")

</div>

May be it's useful to support kind of notations in the hosts file  
too ?

[group1]  
10.2.1.\*

[group2]  
10.2.1.41/24

[group3]  
10.2.1.1-10.2.1.5

---

<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:** [August 16, 2012, 12:19pm UTC](https://forum.ansible.com/t/hosts-with-subnets/11801/2 "2012-08-16T12:19:48Z")

</div>

Ranges in the host file are supported

[group1]  
www.example-[001-100].com

Would generate hosts www.example-001.com through www.example-100.com

You can basically do this to emulate what you need with respect to subnets, but it's also generic so it's not just confined  
to IP addresses.

I noticed this is not on the inventory docs page yet, so I'll make a note to get that in there.

--Michael

---

<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:** [August 16, 2012, 12:44pm UTC](https://forum.ansible.com/t/hosts-with-subnets/11801/3 "2012-08-16T12:44:21Z")

</div>

FWIW, it occurs to me there are reasons we shouldn't allow subnet entry.

Namely, it assumes all hosts in your subnet are taken and should be part of the same group. This may mean managing machines as if they were all the same, or trying to talk to a lot of hosts that aren't there.

If you're really on a static IP setup where you have a lot of homogenous hosts, code-generating your interface file might make sense, or even using the external inventory script feature to maintain your database differently.

Thoughts?

(Also note, www-[000-100].example.com makes a much more sensible example than the one below, typed that kind of fast)
