我将通过编写一个简单的 fabfile来安装check_mk插件,如下所示:
from fabric.api import env, run, roles, execute, parallel
env.roledefs = {
'monitoring': ['192.168.3.118'],
'mk-agent': ['192.168.3.230', '192.168.3.231', '192.168.3.232']
}
@roles('monitoring')
def mk():
run('[ -f check_mk-1.1.12p7.tar.gz ] || wget http://mathias-kettner.de/download/check_mk-1.1.12p7.tar.gz')
run('[ -d check_mk-1.1.12p7 ] || tar zxvf check_mk-1.1.12p7.tar.gz')
run('cd check_mk-1.1.12p7 && sudo ./setup.sh')
@parallel
@roles('mk-agent')
def mk_agent():
run('[ `rpm -qa | grep -c xinetd` -eq 0 ] && sudo yum -y install xinetd.x86_64')
run('sudo rpm -ivh http://mathias-kettner.de/download/check_mk-agent-1.2.0b2-1.noarch.rpm')
def check_mk():
execute(mk)
execute(mk_agent)
但是,你可以猜到,如果xinetd
包已经安装,Fabric 将停止并出现以下错误:
Fatal error: run() received nonzero return code 1 while executing!
Requested: [ `rpm -qa | grep -c xinetd` -eq 0 ] && sudo yum -y install xinetd.x86_64
Executed: /bin/bash -l -c "[ \`rpm -qa | grep -c xinetd\` -eq 0 ] && sudo yum -y install xinetd.x86_64"
Aborting.
在这种情况下有什么解决办法吗?