分布式管理-salt / 未分类 · 2013年12月14日

Salt State

第一 在master 可以看到如下信息
[[email protected] salt]# vim /etc/salt/master
#file_roots:
file_roots:
base:
- /srv/salt/
#- /var/salt/

cd /srv/salt
[[email protected] salt]# pwd
/srv/salt
[[email protected] salt]# cat top.sls
base:
'192.168.1.210':
#- evan.sc
- evan.pack #这个是evan目录下有个pack.sls
#- evan.fc7

mkdir evan
cd evan;

[[email protected] evan]# vim pack.sls
apache:
pkg:
- name: httpd
- installed
service:
- name: httpd
- running
- reload: True
- watch:
- file: /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://fc7/httpd.conf
- user: root
- group: root
- mode: 644
- backup: minion

第二 回来minion
[email protected] salt]# rm -rf /etc/httpd/conf/httpd.conf
[[email protected] salt]# vim /etc/httpd/conf/httpd.conf
[[email protected] salt]# file /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf: ERROR: cannot open `/etc/httpd/conf/httpd.conf’ (No such file or directory)
由上可见 这个文件不在了
第四 to master
[[email protected] salt]# salt 192.168.1.210 state.highstate
192.168.1.210:
———-
State: – pkg
Name: httpd
Function: installed
Result: True
Comment: Package httpd is already installed
Changes:
———-
State: – file
Name: /etc/httpd/conf/httpd.conf
Function: managed
Result: True
Comment: File /etc/httpd/conf/httpd.conf updated
Changes: diff: New file
———-
State: – service
Name: httpd
Function: running
Result: True
Comment: Service reloaded
Changes: httpd: True
第五 然后再回来minion看一下 刚才不小心删除的文件又来了
[[email protected] salt]# file /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf: ASCII English text
参考
http://www.shencan.net/index.php/2013/05/24/saltstack%EF%BC%88%E4%B8%80%EF%BC%89/