salt reactor利用event運行job安裝zabbix-agent

####salt配置react

salt-master:code

  • ip:192.168.10.91

salt-minion:ip

  • id:ops1 ip:192.168.10.91
  • id:192.168.10.92 ip:192.168.10.92
  • id:192.168.10.93 ip:192.168.10.93
  • id:192.168.10.94 ip:192.168.10.94
  • id:192.168.10.95 ip:192.168.10.95

1.master中添加reactor配置cmd

reactor:
  - 'salt/minion/*/start':          salt/minion/*/start event時觸發
    - /srv/reactor/init.sls           運行這個sls

2.編輯/srv/reactor/init.sls文件it

run_state:
  local.state.sls:
    - tgt: {{ data['id'] }}
    - arg:
      - zabbix-agent-init         #運行這個sls

3.重啓master,略io

4.accept一個minion的key或者重啓minion後查看event,在master上運行salt-run state.event pretty=True 能夠看到當salt/minion/192.168.10.94/start 的event出現後,緊接着運行了個zabbix-agent-init的job,待minion運行完後返回了zabbix-agent-init的運行結果event

salt/minion/192.168.10.94/start {           #發現以下event
    "_stamp": "2016-03-31T14:25:06.000282", 
    "cmd": "_minion_event", 
    "data": "Minion 192.168.10.94 started at Thu Mar 31 22:25:05 2016", 
    "id": "192.168.10.94", 
    "pretag": null, 
    "tag": "salt/minion/192.168.10.94/start"
}
salt/event/new_client   {
    "_stamp": "2016-03-31T14:25:06.120657"
}
20160331222506137435    {
    "_stamp": "2016-03-31T14:25:06.137938", 
    "minions": [
        "192.168.10.94"
    ]
}
salt/job/20160331222506137435/new       {             #執行zabbix-agent-init.sls的job
    "_stamp": "2016-03-31T14:25:06.138985", 
    "arg": [
        "zabbix-agent-init"
    ], 
    "fun": "state.sls", 
    "jid": "20160331222506137435", 
    "minions": [
        "192.168.10.94"
    ], 
    "tgt": "192.168.10.94", 
    "tgt_type": "glob", 
    "user": "root"
}
......
salt/job/20160331222506137435/ret/192.168.10.94 {
    "_stamp": "2016-03-31T14:25:29.774154", 
    "cmd": "_return", 
    "fun": "state.sls", 
    "fun_args": [
        "zabbix-agent-init"
    ], 
    "id": "192.168.10.94", 
    "jid": "20160331222506137435", 
    "out": "highstate", 
    "retcode": 0, 
    "return": {
......
    }, 
    "success": true   執行成功
}
相關文章
相關標籤/搜索