saltstack配置管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack配置管理相关的知识,希望对你有一定的参考价值。
状态模块:
https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#module-salt.states.file
[[email protected] ~]# grep -v ‘^$‘ /etc/salt/master |grep -v ‘#‘
client_acl:
luo:
- test.ping
- network.*
file_roots: #top.sls路径,可以写多个
base: #但是只读取base路径
- /srv/salt/base
test:
- /srv/salt/test
prod:
- /srv/salt/prod
pillar_roots:
base:
- /srv/pillar
mysql.host: ‘192.168.43.118‘
mysql.user: ‘salt‘
mysql.pass: ‘Myq1231!‘
mysql.db: ‘salt‘
mysql.port: 3306
[[email protected] ~]# systemctl restart salt-master
[[email protected] ~]# mkdir /srv/salt/{base,test,prod}
[[email protected] salt]# ls
apache.sls base prod test top.sls
[[email protected] salt]# mv apache.sls top.sls base/
编写基本文件管理:
[[email protected] ~]# mkdir /srv/salt/base/files
[[email protected] base]# pwd
/srv/salt/base
[[email protected] base]# vim dns.sls
[[email protected] base]# cat dns.sls
/etc/resolv.conf:
file.managed: #file模块的managed方法
- source: salt://files/resolv.conf #路径,salt://=/srv/salt/base ,files新建的文件。
- user: root #用户
- group: root #用户组
- mode: 777 #权限
[[email protected] base]# cp /etc/resolv.conf ./files/
[[email protected] base]# vim files/resolv.conf
[[email protected] base]# cat files/resolv.conf
nameserver 192.168.43.1
[[email protected] base]# salt ‘*‘ state.sls dns state状态模块的sls方法,dns为状态名,可以任意写。
192.168.43.118:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: True
Comment: File /etc/resolv.conf updated
Started: 00:18:45.928344
Duration: 18.082 ms
Changes:
----------
diff:
---
+++
@@ -1,3 +1 @@
-# Generated by NetworkManager
-search com
nameserver 192.168.43.1
mode:
0777
Summary
------------
Succeeded: 1 (changed=1)
[[email protected] base]# pwd
/srv/salt/base
[[email protected] base]# vim top.sls
[[email protected] base]# cat top.sls
base:
‘*‘:
- dns
[[email protected] files]# pwd
/srv/salt/base/files
[[email protected] files]# vim resolv.conf
[[email protected] files]# cat resolv.conf
#jjjjjjjjjjjjjjjjjj
nameserver 192.168.43.1
[[email protected] base]# salt ‘*‘ state.sls dns state状态模块的sls方法,dns为状态名,可以任意写。
192.168.43.118:
----------
ID: /etc/resolv.conf
Function: file.managed
Result: True
Comment: File /etc/resolv.conf updated
Started: 00:26:07.017848
Duration: 24.144 ms
Changes:
----------
diff:
---
+++
@@ -1 +1,2 @@
+#jjjjjjjjjjjjjjjjjj
nameserver 192.168.43.1
Summary
------------
Succeeded: 1 (changed=1)
Failed: 0
[[email protected] base]# cat /etc/resolv.conf
#jjjjjjjjjjjjjjjjjj
nameserver 192.168.43.1
以上是关于saltstack配置管理的主要内容,如果未能解决你的问题,请参考以下文章