Use regular expressions to select set of mcollective hostsBy neokrates, written on September 12, 2013
Consider you have large number of hosts and want to use one criteria to apply your command to specific set of them.
In my simple case I just want to use hostname as a criteria, adding some regualar expression to have the set of numbered hosts :
All my hosts have the folloing common string in them : my-uniq-hostname
List what is under puppet / mcollective :
> mco ping|grep my-uniq-hostname
Gives me :
> my-uniq-hostname-08-hh1.my.domain.net time=252.90 ms my-uniq-hostname-04-hh1.my.domain.net time=254.47 ms my-uniq-hostname-05-hh1.my.domain.net time=255.79 ms
Now, I want to check the puppet status for this hosts . So, how do I apply the
service puppet status command to all of them?
> mco shell 'service puppet status' -F "hostname=/my-uniq-hostname-0[0-9]-hh1.my.domain.net/"
– “-F” is for “fact”, so apply the same command to all hosts matching given fact.
– “hostname” is the fact to be matched
– “//” scope denotes that matching target is regular expression
– “[0-9]” is the regular expression part, i.e. matching 0 to 9 here
Inhere I use “mco shell” command which is not standard for mcollective. But matching shall work the same way for standard commands and facts.
To learn more about the facts you can match first, use
inventory command , like :
> mco inventory my-uniq-hostname-08-hh1.my.domain.net|less
By learning available facts first you can the target the sets of systems using common facts .
INCOMING SEARCH TERMS