1.在/srv/salt目錄下建立top.sls文件
cd /srv/salt
touch top.sls
2.編輯sls文件
vim hosts.sls
/tmp/aaa.hosts : //name,能夠宿便寫,可是若是這裏不寫同步路徑信息的話,須要在後面加上- name: /tmp/aaa.hosts file.managed: //指定使用的salt模塊的名稱 - source: salt://etc/hosts //同步的源在哪
- user: root
- group: root
- mode: 600
保存退出
vim top.sls
base: //這個是top.sls文件的固定格式,總共有三個:base dev和prod,跟你以前在master配置文件使用哪一個級別的根目錄有關(參看salt的文件系統配置)
'*': //表明使用sls的機器 - hosts //表明使用的自定義sls文件的名稱是什麼
保存退出
3.下發配置文件
cp /etc/hosts /srv/salt/etc/hosts //建立/etc/hosts文件
salt '*' state.highstate //調用top.sls
salt '*' state.sls hosts //直接調用hosts.sls
以上兩種方法均可如下發配置文件到minion端
4.測試,當hosts.sls文件mv到非根目錄下時如何下發配置
[iyunv@Admin1-saltstack etc]# cd /srv/salt/
[iyunv@Admin1-saltstack salt]# ls
etc hosts.sls top.sls
[iyunv@Admin1-saltstack salt]# mkdir hosts
[iyunv@Admin1-saltstack salt]# mv hosts.sls hosts
[iyunv@Admin1-saltstack salt]# echo "bbbbbbb" >> etc/hosts
[iyunv@Admin1-saltstack salt]# salt '*' state.sls hosts.hosts
Admin3-saltstack.littlebee.com:
----------
ID: /tmp/aaa.hosts
Function: file.managed
Result: True
Comment: File /tmp/aaa.hosts updated
Started: 14:52:35.309405
Duration: 7.627 ms
Changes:
----------
diff:
---
+++
@@ -1,3 +1,4 @@
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
aaaaaaaaaa
+bbbbbbb
Summary
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Admin2-saltstack.littlebee.com:
----------
ID: /tmp/aaa.hosts
Function: file.managed
Result: True
Comment: File /tmp/aaa.hosts updated
Started: 14:52:34.936313
Duration: 7.775 ms
Changes:
----------
diff:
---
+++
@@ -1,3 +1,4 @@
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
aaaaaaaaaa
+bbbbbbb
Summary
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
5.關於init.sls
當目錄下找不到sls文件時,會默認執行init.sls文件裏的內容vim