Use regular expressions to select set of mcollective hosts

By neokrates, written on September 12, 2013

howto

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 697 views
Rate it
Ad
Poll
  • Your favorite browser?

    View Results

    Loading ... Loading ...
Feeds:
  • 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 :

> 
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/" 

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 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 .

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'


TAGS

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS


Leave a Reply