getting salt mine to report eth0 IP addresses for minions in a specific role with 2015.2 version

693 views
Skip to first unread message

UnlimitedMoops

unread,
Mar 27, 2015, 4:00:44 PM3/27/15
to salt-...@googlegroups.com
hi all..

I'm running a salt 2015.2 master/minion on Ubuntu Trusty 14.04.

I would like a simple way to organize minions into roles then gather the IP addresses from them and append them to the end of a configuration file which is deployed to each.

The example at http://docs.saltstack.com/en/latest/topics/mine/ seems to be relevant. I'm also using the external pillar mechanism to assign roles to the minions with the ext_pillar_first setting in the master file as described by Develop Ninja at http://devop.ninja/configuration%20management/2015/03/01/beyond-grains-roles-with-an-external-pillar/ . I would like to avoid putting salt configuration files on the minion if possible.

The minimal (i think) configuration files with an install.sh and a vagrant environment to reproduce the issue are on gist at https://gist.github.com/wrabbit-revisited/0bc0f54b4b9dd5f6ce28 .

The salt-minion and salt-master both come up as services automatically when the VMs boot. If i run a pillar.items from the command line, the roles are not output properly. If i terminate the salt-master service then restart it in foreground with debugging on it prints the roles. I didn't expect this.

The roles seem to be working, but I'm not sure how to get salt mine working to generate a list of eth0 addresses for all minions that are assigned a given role.  If somebody knows how to print the salt mine content on the command line or otherwise debug it without swimming in the Python details i would appreciate it. At this point i don't feel confident enough to file it as an issue.. it may be simple to fix.

thanks!

UnlimitedMoops

unread,
Mar 28, 2015, 8:42:41 AM3/28/15
to salt-...@googlegroups.com
btw i see some unusual behavior. On startup of the VM the salt-master service is running. After accepting the minion01 key and running 

    sudo salt '*' pillar.items

the contributions from ext_pillar are not present. So, just by chance, i stop the service:

    sudo service salt-master stop
    sudo salt-master -l debug

Now the pillar.items returns the ext_pillar roles. Weird. So, to confirm:

    Ctrl-C to stop salt-master
    sudo service salt-master start
    sudo salt '*' pillar.items

and, once again, ext_pillar roles are absent. I've done this twice to confirm it's reproducible.

Florian Ermisch

unread,
Mar 29, 2015, 4:33:11 AM3/29/15
to salt-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi David,

You can set a special pillar-key "mine_functions" to list the functions a minion should run to populate the salt mine. But you can't access pillar before rendering pillar is done (and I think this limitation still applies with an external pillar). So you'd have to add both role and mine_functions in one go. If you don't want to list all the mine functions for every minion you can use a templated include in your pillar passing the minion's roles to the template which decides what to put into mine_functions based on the role(s).

Also don't forget Pillar data is cached on the minions. So you want to run `saltutils.pillar_refresh` and then `mine.update` on all minions before trying to populate your file (although both functions get run on minion start-up).

Then you could just use s/t like

{% for server, addrs in salt['mine.get']('role:server', 'network.ip_addrs', expr_form='pillar').items() %}
{{ server }} {{ addrs[0] }}
{% endfor %}

Regards, Florian
>--
>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/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQFTBAEBCAA9BQJVF7i9NhxGbG9yaWFuIEVybWlzY2ggPGZsb3JpYW4uZXJtaXNj
aEBhbHVtbmkudHUtYmVybGluLmRlPgAKCRAu8tzCHoBI/ei5B/9iHr/6/2YyPssV
B5pBup92fWJuF7cF8BtE1cLkGKBy6ZHVuKrvTUbdtf9Ok+qpv2putdIBwLdVYOFT
WGEZrYH7JcSE7LKzZ4r+A0JhboptARR0NWoRaMBB714tomDRXi1gKZnaMzBxFGY8
NkGTt+hP1y8n93Ci+Y4NHSYVImfs741frHlGuGAMOZtwiD1cihbAnpshx6TXGZQV
XS5a6sN48+lU63HFziNDAxLZ2s8vfCwQuJVN2+8lVLPblDhJSKdSyg3Rj0LViLem
ADIoDRnhFRp5xmX3dNoyqWeDfn25RaXbNKBjHcsXk0PnxgnYDjHDscFTmDvC8y3/
9kOOnpaP
=JV5y
-----END PGP SIGNATURE-----

UnlimitedMoops

unread,
Mar 29, 2015, 10:19:22 AM3/29/15
to salt-...@googlegroups.com, florian...@alumni.tu-berlin.de
Thanks Florian! The syntax of your template worked. This gets me part of the way there. I have to assign a persistent unique ID to each minion, but that's handled in another question: "how do i place a unique id for each minion in a file?".

Reply all
Reply to author
Forward
0 new messages