Targeting minions based on pillar data

509 views
Skip to first unread message

Kevin Dodge

unread,
Nov 28, 2012, 7:10:59 PM11/28/12
to salt-...@googlegroups.com
On this page https://salt.readthedocs.org/en/latest/topics/pillar/index.html it mentions that you can target minons by referencing pillar data by using  salt -I 'key:value' test.ping.     I am trying to do this and cant seem to get it to work the way I expect it to.

For example, I have this pillar data set.   

{% if grains['host'] == 'QA' or grains['host'] == 'QA2' %}
webapps:
   - helloworld
   - GoBub
{% endif %}

How would I target a minion based on this pillar data?
  

Assuming that the targeting above is possible, is it possible to do matching in my top.sls based on pillar data?   If so how do I do that.

Thomas S Hatch

unread,
Nov 29, 2012, 12:50:24 PM11/29/12
to salt-...@googlegroups.com
If I am not mistaken:

salt -I 'webapps:helloworld' should match since it will check for indices in a list, let me know it this works, I may need to look at the code to see if there are any potential probelms

Kevin Dodge

unread,
Nov 29, 2012, 2:59:58 PM11/29/12
to salt-...@googlegroups.com
I was able to solve part of my problems after I found this link http://docs.saltstack.org/en/latest/ref/states/top.html

This link made it so I could setup my top.sls to look for a pillar for matching.   I was not able to check for nested values though, only single values.   So for the solution I did this.

{% if grains['host'] == 'QA' or grains['host'] == 'QA2' %}
webapps-on: True
webapps:
   - helloworld
   - GoBub
{% endif %}

Then in my top.sls I was able to match this

  'webapps-on:True':
    - match: pillar

Note, I was not able to do this

  'webapps:helloworld':
    - match: pillar



Unfortunately I have not gotten the command line selector working, even with a single level property.

salt -I 'webapps-on:True' test.ping    -- this does not work for me. 

Alec Koumjian

unread,
Nov 29, 2012, 8:01:24 PM11/29/12
to salt-...@googlegroups.com
It is because the literal value is not "helloworld" but is a list of values ['helloworld','GoBub'] ?

Kevin Dodge

unread,
Nov 30, 2012, 1:27:17 PM11/30/12
to salt-...@googlegroups.com
I was worried that it would require me to list the literal value.   I guess I was hoping it would use is defined if it was a list or dict object.

Still, I still don't understand why I cant target minions from the command line using pillars.  Has anyone else tried to make sure it is working?

Thomas S Hatch

unread,
Nov 30, 2012, 2:54:04 PM11/30/12
to salt-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages