标签:判断 环境 tool 目录 多个 需要 restart wing 返回结果
apache-install第1行是声明,第2行pkg是状态模块,installed是方法。
apache-service,是服务状态管理。
apache-install: pkg.installed: - name: httpd apache-service: service.running: - name: httpd - enable: True
salt ‘*node2*‘ state.sls apache
执行后看返回结果:上边是安装,下边是启动。看change那行,改变了几个地方,可以判断执行了几个ID。
linux-node2.example.com: ---------- ID: apache-install Function: pkg.installed Name: httpd Result: True Comment: The following packages were installed/updated: httpd Started: 09:46:59.759738 Duration: 9266.372 ms Changes: ---------- apr: ---------- new: 1.4.8-7.el7 old: apr-util: ---------- new: 1.5.2-6.el7 old: httpd: ---------- new: 2.4.6-97.el7.centos old: httpd-tools: ---------- new: 2.4.6-97.el7.centos old: mailcap: ---------- new: 2.1.41-2.el7 old: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled, and is running Started: 09:47:09.032003 Duration: 189.507 ms Changes: ---------- httpd: True Summary for linux-node2.example.com ------------ Succeeded: 2 (changed=2) Failed: 0 ------------ Total states run: 2 Total run time: 9.456 s
这时可以到node2上去验证了,如果手动在node2上停止httpd,再在master上执行 salt ‘linux-node2*‘ state.sls apache可以看到只改变了一个,会把服务启动起来。
多层配置目录:
可以在base下创建多个目录,然后把相应的状态文件到到相应的目录里。
[root@linux-node1 base]# pwd /srv/salt/base [root@linux-node1 base]# mkdir web [root@linux-node1 base]# mv apache.sls web/ [root@linux-node1 base]# salt "linux-node2*" state.sls web.apache
master文件里默认文件就是base下的top.sls,不需要修改,就直接用这个文件。
vim /srv/salt/base/top.sls:
base: ‘linux-node2.example.com‘: - web.apache ‘linux-node3.example.com‘: - web.apache
执行:
salt ‘*‘ state.highstate
标签:判断 环境 tool 目录 多个 需要 restart wing 返回结果
原文地址:https://www.cnblogs.com/amhk/p/14183118.html