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到非根目录下时如何下发配置
[[email protected] etc]# cd /srv/salt/
[[email protected] salt]# ls
etc hosts.sls top.sls
[[email protected] salt]# mkdir hosts
[[email protected] salt]# mv hosts.sls hosts
[[email protected] salt]# echo "bbbbbbb" >> etc/hosts
[[email protected] 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文件里的内容