1

I am using SaltStack on my linux boxes and want to define nodegroups. I know about compound matching and minion lists, etc.

This is what I need, and it works this way, but that's hard to maintain with lots of servers

nodegroups:
  group1: 'srv1,srv2,srv3,srv4,dev1,dev2,stage1,stage2'
  

To keep it simple, I'm trying to define them this way:

nodegroups:
  group1: 'srv*,dev*,stage*'

But I can't find a way to do this right. Any ideas?

-=EDIT=-

I tried Dan Garthwaites solution, but it didn't work. I even tried it on my private dev server, which has Salt version 2014.1.4 installed. This is what I get.

Trying as normal list (full hostnames)

fmohr@salt-master:~$ sudo salt -v -C 'L@dns01,apache' test.ping
Executing job with jid 20140708072832751715
-------------------------------------------

dns01:
    True
apache:
    True

with one wildcard

fmohr@salt-master:~$ sudo salt -v -C 'L@dns*,apache' test.ping
Executing job with jid 20140708072837257646
-------------------------------------------

apache:
    True

with all wildcards

fmohr@salt-master:~$ sudo salt -v -C 'L@dns*' test.ping
No minions matched the target. No command was sent, no jid was assigned.

fmohr@salt-master:~$ sudo salt -v -C 'L@dns*,apach*' test.ping
No minions matched the target. No command was sent, no jid was assigned.

I don't think you can use wildcards in lists, but I have no clue how to get salt to target dns* and apach* (as an example).

mohrphium
  • 615
  • 2
  • 9
  • 16

3 Answers3

3

you should use or to connect them, like this:

nodegroups:
    group1: 'srv* or dev* or stage*'

salt -C 'srv* or dev* or stage*' test.ping

tested on my machine.

CatOverflow
  • 146
  • 2
2

Node groups use compound matching as defined here:

http://docs.saltstack.com/en/latest/topics/targeting/compound.html

Your answer is:

nodegroups:
  group1: L@srv*,dev*,stage*

Keep in mind you can also use grains and/or pillars to target minions via the compound matcher.

Dan Garthwaite
  • 2,922
  • 18
  • 29
0

I did it with grains now. I just added

grains:
  group: groupname

in the /etc/salt/minion.d/minion.conf on my minions. It's not really what I wanted since this defines which roles the minion gets on the minion side, which is not optimal from a security perspective (plus it would be more convenient to define all groups on the master.)

On the plus side, I can set the grain for servers that don't belong to any groups to undefined and it's easier to get a list of all undefined servers.

Thanks for the help. I'll let this stay as unresolved, since it's not really solved (if someone knows how to do this on the master, please tell me)

mohrphium
  • 615
  • 2
  • 9
  • 16