puppet MCollective 命令行使用

【puppet MCollective常用命令行 】

 #mco inventory hotpu

Inventory for hotpu:

Server Statistics:
Version: 2.8.4
Start Time: Mon May 30 18:53:09 +0800 2016
Config File: /etc/mcollective/server.cfg
Collectives: mcollective
Main Collective: mcollective
Process ID: 2260
Total Messages: 1
Messages Passed Filters: 1
Messages Filtered: 0
Expired Messages: 0
Replies Sent: 0
Total Processor Time: 91.79 seconds
System Time: 72.83 seconds

Agents:
discovery filemgr nrpe
package puppet rpcutil
service shell

………………

#mco inventory hotpu | awk '/Facts:/','/^$/'
Facts:
architecture => x86_64
augeasversion => 1.0.0
bios_release_date => 08/10/2007
bios_vendor => Dell Inc.
bios_version => 1.5.1

………………

 #mco facts hostname
Report for fact: hostname

computer001   found 1 times
computer002  found 1 times
computer003  found 1 times

cat inventory.mc

inventory do
format "%20s %8s %10s %-20s"
fields {[ identity, facts["architecture"],facts["operatingsystem"], facts["operatingsystemrelease"]
]}
end

#mco inventory --script inventory.mc
hotpu x86_64 CentOS 6.6
computer001 x86_64 CentOS 6.5
computer002 x86_64 CentOS 6.7
computer003 x86_64 CentOS 6.7

#mco plugin doc mc
mc
==

MCollective Broadcast based discovery

Author: R.I.Pienaar <rip@devco.net>
Version: 0.1
License: ASL 2.0
Timeout: 2
Home Page: http://marionette-collective.org/

DISCOVERY METHOD CAPABILITIES:
Filter based on configuration management classes
Filter based on system facts
Filter based on mcollective identity
Filter based on mcollective agents
Compound filters combining classes and facts

#echo "computer001" > host && mco rpc rpcutil ping --disc-method flatfile --disc-option ./host
Discovering hosts using the flatfile method .... 1

* [ ============================================================> ] 1 / 1
computer001
Timestamp: 1464848863

Finished processing 1 / 1 hosts in 29.80 ms

 #mco find --with-identity /c/
mco find --with-fact operatingsystem=CentOS 

#查看操作系统为CentOS的MC 服务端机器列表

mco find --with-agent package 
mco ping --select "operatingsystem=CentOS and !environment=dev"
 mco facts osfamily --limit 5 --with-class base
mco package status sudo --batch 10 --batch-sleep 20

#查看软件包状态

puppet tagged 用法

【puppet tagged 用法】

puppet tag 官方参考文档:https://docs.puppet.com/puppet/latest/reference/lang_tags.html

  • tag元参数,用于标签资源;
  • tag函数,用于标签容器;
  • tagged函数,用于判断一个容器,是否有某个标签,即用于检查tag函数。

 


node 'default' {
tag('puppetclient')
class {'role::test': }
}

class role::test {
if tagged('puppetclient') {
notify { '  role::test  class was tagged.': }
}
}

puppet MCollective 插件安装

【puppet MCollective  插件安装】

MCollective  插件安装常见有两种安装方式:

  •   在线使用yum安装

添加puppet 官方的yum源,然后使用yum来安装,示例:

yum install mcollective-filemgr-agent mcollective-filemgr-client  mcollective-filemgr-common  mcollective-iptables-agent mcollective-iptables-client
  •   离线安装方式a.

要求某台机器安装有如下软件包:rpm-build git的工具,本机已经安装MCollective package 插件,使用这些工具将原来下载下来的源文件打包成rpm格式,再作分发安装。 Mcollectvie 插件过程安装如示例:

 #git clone https://github.com/cegeka/mcollective-shell-agent #克隆git仓库
cd mcollective-shell-agent
[root@hotpu mcollective-shell-agent]# mco plugin package .
[root@hotpu mcollective-shell-agent]# ls -l *.rpm
[root@hotpu mcollective-shell-agent]# rpm -ivh mcollective-shell-command-common-1.0-1.el6.noarch.rpm
Preparing... ########################################### [100%]
1:mcollective-shell-comma########################################### [100%]
[root@hotpu mcollective-shell-agent]# rpm -ivh mcollective-shell-command-client-1.0-1.el6.noarch.rpm
Preparing... ########################################### [100%]
1:mcollective-shell-comma########################################### [100%]
[root@hotpu mcollective-shell-agent]# rpm -ivh mcollective-shell-command-agent-1.0-1.el6.noarch.rpm
Preparing... ########################################### [100%]
1:mcollective-shell-comma########################################### [100%]

  •   离线安装方式b

将下载目录的对应文件复制到:/usr/libexec/mcollective/mcollective/ 对应目录下即可。

安装完插件后,需要重新启动mcollective 服务。