saltstack的状态文件
最近发现很多服务器上没有配置ntp服务器指向,简单写个计划任务,然后通过状态文件下发思路:
a)准备好需要下发的文件
b)编辑sls文件
c)修改top.sls,添加信息进去
# cat /var/spool/cron/root
*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101>/dev/null 2>&1
# cd /etc/salt/states/
# ls
initprodtop.sls
# cd init/
# ls
fileslimit.slspkg.sls
# cp limit.sls ntp-crontab.sls
# ls
fileslimit.slsntp-crontab.slspkg.sls
# cd files/
# cp /var/spool/cron/root .
# pwd
/etc/salt/states/init/files
# cat root
*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101>/dev/null 2>&1
# mv root ntp-crontab.conf
# cat ntp-crontab.conf
*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101>/dev/null 2>&1
# cd ..
# ls
fileslimit.slsntp-crontab.slspkg.sls
# cat /etc/salt/states/init/ntp-crontab.sls
ntp-crontab-config:
file.managed:
- name: /var/spool/cron/root
- source: salt://init/files/ntp-crontab.conf
- user: root
- group: root
- mode: 644
计划任务更新执行结果:
# salt '*' state.highstate
node01.saltstack.com:
----------
ID: pkg.init
Function: pkg.installed
Name: mtr
Result: True
Comment: Package mtr is already installed.
Started: 21:09:06.608808
Duration: 4265.514 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: nmap
Result: True
Comment: Package nmap is already installed.
Started: 21:09:10.874647
Duration: 0.685 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: lrzsz
Result: True
Comment: Package lrzsz is already installed.
Started: 21:09:10.875446
Duration: 0.583 ms
Changes:
----------
ID: limit-conf-config
Function: file.managed
Name: /etc/security/limits.conf
Result: True
Comment: File /etc/security/limits.conf is in the correct state
Started: 21:09:10.879350
Duration: 4.1 ms
Changes:
----------
ID: ntp-crontab-config
Function: file.managed
Name: /var/spool/cron/root
Result: True
Comment: File /var/spool/cron/root updated
Started: 21:09:10.883639
Duration: 9.342 ms
Changes:
----------
diff:
New file
mode:
0644
Summary
------------
Succeeded: 5 (changed=1)
Failed: 0
------------
Total states run: 5
node02.saltstack.com:
----------
ID: pkg.init
Function: pkg.installed
Name: mtr
Result: True
Comment: Package mtr is already installed.
Started: 21:09:07.831431
Duration: 4292.2 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: nmap
Result: True
Comment: Package nmap is already installed.
Started: 21:09:12.123977
Duration: 0.714 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: lrzsz
Result: True
Comment: Package lrzsz is already installed.
Started: 21:09:12.124798
Duration: 0.426 ms
Changes:
----------
ID: limit-conf-config
Function: file.managed
Name: /etc/security/limits.conf
Result: True
Comment: File /etc/security/limits.conf is in the correct state
Started: 21:09:12.128235
Duration: 5.165 ms
Changes:
----------
ID: ntp-crontab-config
Function: file.managed
Name: /var/spool/cron/root
Result: True
Comment: File /var/spool/cron/root updated
Started: 21:09:12.133621
Duration: 8.761 ms
Changes:
----------
diff:
New file
mode:
0644
Summary
------------
Succeeded: 5 (changed=1)
Failed: 0
------------
Total states run: 5
检查结果:
# cd /var/spool/cron/
# ls
root
# cat root
*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101>/dev/null 2>&1
# cat /var/spool/cron/root
*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101>/dev/null 2>&1
通过对比会发现,与master的下发文件一致
页:
[1]