Create hosts file from list of minions

1,342 views
Skip to first unread message

Ran Leibman

unread,
Feb 10, 2013, 4:40:53 AM2/10/13
to salt-...@googlegroups.com
Hi All

I'm trying to find a way to create a hosts file from the list of minion I have.
I thought about using file.manged with jinja template but I don't know how to list my minions and their ips from there.

Does someone have any idea from where to start ?
Many Thanks
Ran

Umberto Nicoletti

unread,
Feb 10, 2013, 7:39:11 AM2/10/13
to salt-...@googlegroups.com
This template


which generates a dns zone file should help you get started.

hth,
Umberto

Ran Leibman

unread,
Feb 10, 2013, 8:27:52 AM2/10/13
to salt-...@googlegroups.com
Thanks for the quick reply Umberto
this is a good solution but if one of the minions are down I won't get it's data and also it's a bit chatty.
is it possible to get a list of minion by grains from a template ?

Mrten

unread,
Feb 12, 2013, 6:13:22 AM2/12/13
to salt-...@googlegroups.com
On 10/2/2013 14:27 , Ran Leibman wrote:
> Thanks for the quick reply Umberto
> this is a good solution but if one of the minions are down I won't get
> it's data and also it's a bit chatty.
> is it possible to get a list of minion by grains from a template ?
>
> On Sunday, February 10, 2013 2:39:11 PM UTC+2, Umberto Nicoletti wrote:
>
> This template
>
> https://gist.github.com/unicolet/3987451

Dunno if it's widely known but I'd like to share that jinja can remove
whitespace before opening- and closing tags by adding a - to the tag:

{%- removes the whitespace before the tag
-%} removes the whitespace following tag

Would make the shown gist a bit more readable, I guess.

http://jinja.pocoo.org/docs/templates/#whitespace-control

(used this for readable /etc/network/interfaces)

M.

Dan Garthwaite

unread,
Feb 13, 2013, 9:26:31 AM2/13/13
to salt-...@googlegroups.com, mrten+s...@ii.nl
Good tip.  I add a comment to the gist with the code + whitespace, like this:

@ in soa localhost. root 1 3H 15M 1W 1D
  ns localhost.
{%- set nets=salt['publish.publish']('*','network.interfaces') -%}
{%- for n in nets -%}
    {%- set pdata=salt['publish.publish'](n,'pillar.data') -%}
    {%- if pdata.has_key(n) -%}
        {%- if pdata[n].has_key('zone') -%}
            {%- if pdata[n]['zone']=='linuxservers' %}
{{ n }} IN      A       {{ nets[n]['eth0']['inet'][0]['address'] }} 
            {% endif -%}
        {%- endif -%}
     {%- endif -%}
{%- endfor %}

David Boucha

unread,
Feb 13, 2013, 1:08:21 PM2/13/13
to salt users list
Another possible option is to use a database for the external job cache, such as the mongo or mysql external job cache. Minions will automatically send their returns to that database. Then you can run a query on that database to get their ips from there. If all the minions have responded to a query like "salt \* network.interfaces", then their information will appear in that database, even if that minion is currently down or unavailable.

This might not be useful in all types of infrastructures, but I thought I'd mention that possibility if you're concerned about temporarily downed minions missing from your hosts file.


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

office 801-305-3563
da...@saltstack.com | www.saltstack.com

Ran Leibman

unread,
Feb 14, 2013, 3:14:25 AM2/14/13
to salt-...@googlegroups.com
Thanks for the replies, but I think that for my environment I'll choose a different approach.
The salt server will be the one that provision my servers and set their ips so I think I'll get my data from there since its the most consistent.
I'll just need to think about what will be the best way for it.

Thanks a lot =)

Danil Gusev

unread,
Apr 29, 2013, 4:30:25 PM4/29/13
to salt-...@googlegroups.com
Ran, do you found more elegant solution?

Ran Leibman

unread,
Apr 29, 2013, 5:50:31 PM4/29/13
to salt-...@googlegroups.com
Well not so much I'm afraid ...
I decided to create a zone file like Umberto stated above but instead of using published commands I use pillar.
I have a pillar file hosts.sls that has all the minion ids and their ip addresses, each time I provision/delete a host I'm updating it and rerun the dns state on my dns servers, which makes them update the zone file according to the pillar file.
because I'm using a dedicated pillar file to this its really easy to manage it via the yaml module for python..

I came to realize its a bit of work, but it make sure that I don't miss minions that are not available while issuing the publish commands.

I'll be happy to get more suggestions though =)


You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/1ENmUKIy5EE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Ran Leibman

Mrten

unread,
Apr 29, 2013, 5:57:58 PM4/29/13
to salt-...@googlegroups.com
On 29/4/2013 23:50 , Ran Leibman wrote:
> Well not so much I'm afraid ...
> I decided to create a zone file like Umberto stated above but instead of
> using published commands I use pillar.
> I have a pillar file hosts.sls that has all the minion ids and their ip
> addresses, each time I provision/delete a host I'm updating it and rerun
> the dns state on my dns servers, which makes them update the zone file
> according to the pillar file.
> because I'm using a dedicated pillar file to this its really easy to
> manage it via the yaml module for python..
>
> I came to realize its a bit of work, but it make sure that I don't miss
> minions that are not available while issuing the publish commands.
>
> I'll be happy to get more suggestions though =)
>

Not trying to steal Thomas' thunder here but there is a feature coming
up in the (a?) next version called 'mine' that might just be your ticket.

https://github.com/saltstack/salt/issues/4254

I really don't know anything about it but my bug seemed to match your
usecase.

M.

Ran Leibman

unread,
Apr 29, 2013, 6:03:53 PM4/29/13
to salt-...@googlegroups.com
Wow that will make my life easier ...
looks like there are still surprises to come, I'll open my ears for this one.

thanks =)


--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/1ENmUKIy5EE/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Ran Leibman

Thomas S Hatch

unread,
Apr 29, 2013, 6:19:07 PM4/29/13
to salt-...@googlegroups.com
Woah! Mrten stole my thunder!!
Just kidding, I am glad people are watching here, and yes, the mine system will make generating distributed hosts files VERY easy, we should add a state that reads in mine data and does it for you.

Thomas S. Hatch  |  Founder, CTO


5272 South College Drive, Suite 301 | Murray, UT 84123

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.

Ran Leibman

unread,
Apr 30, 2013, 1:42:18 PM4/30/13
to salt-...@googlegroups.com

Thomas when will mine be available ? Which version ?
I would really like to play with it :-)

Thomas S Hatch

unread,
Apr 30, 2013, 4:47:29 PM4/30/13
to salt-...@googlegroups.com
It is in git head right now if you wantto play with it, and it will be in 0.15.0

Thomas S. Hatch  |  Founder, CTO


5272 South College Drive, Suite 301 | Murray, UT 84123


David Dyball

unread,
Apr 30, 2013, 5:11:15 PM4/30/13
to salt-...@googlegroups.com
Just wondering if there is any docs for `mine` in got yet? If not can you point me in the direction of the source file so I can try and understand it :-P

David Boucha

unread,
Apr 30, 2013, 5:15:51 PM4/30/13
to salt users list


On Tue, Apr 30, 2013 at 3:11 PM, David Dyball <david....@gmail.com> wrote:
Just wondering if there is any docs for `mine` in got yet? If not can you point me in the direction of the source file so I can try and understand it :-P
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

Reply all
Reply to author
Forward
0 new messages