Use regular expressions to select set of mcollective hosts

By neokrates, written on September 12, 2013


  • Join date: 11-30-99
  • Posts: 224
View Counter:
Rate it
  • What would describe state of logging infrastructure of your enterprise best?

    View Results

    Loading ... Loading ...
  • bodytext bodytext bodytext

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 :

>         time=252.90 ms         time=254.47 ms         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]" 

Explained :
– “-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

Remark :
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|less 

By learning available facts first you can the target the sets of systems using common facts .

Be Sociable, Share!
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
0 votes 'YES'  0 votes 'NO'


Be Sociable, Share!


Leave a Reply