forked from ljb-2000/saltweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saltstack
89 lines (84 loc) · 2.13 KB
/
saltstack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
saltstack集中管理crontab定时任务、系统用户、文件同步
[root@mod ]# vim /etc/salt/master 在最后添加以下内容
file_roots:
base:
- /srv/salt
pillar_roots:
base:
- /srv/pillar
[root@mod ]# mkdir /srv/pillar
[root@mod ]# mkdir /srv/salt
[root@mod ]# mkdir /srv/salt/files
[root@mod ]# cat /srv/pillar/top.sls
base:
'*':
- schedule
[root@mod salt]# cat /srv/pillar/schedule.sls
schedule:
highstate:
function: state.highstate
minutes: 2
[root@mod pillar]# salt '*' saltutil.refresh_pillar #注意:每次修改pillar中的变量或参数都需要执行同步pillar命令
[root@mod pillar]# cat /srv/salt/top.sls
base:
'*':
- cron
# - user
# - files
# 'group1':
# - match: nodegroup
# - user
[root@mod pillar]# cat /srv/salt/cron.sls
add_cron:
cron.present:
- name: "/usr/sbin/ntpdate tiger.sina.com.cn >/dev/null 2>&1"
- user: root
- minute: '*/10'
#del_cron:
# cron.absent:
# - name: "/usr/sbin/ntpdate tiger.sina.com.cn >/dev/null 2>&1"
# - user: hhr
[root@mod pillar]# cat /srv/salt/user.sls
huanghuirong:
user.present:
- password: '$1$HtvZo6N2$gMik5ejbJEH6DoUzhXpKz1'
- shell: /bin/bash
- home: /home/huanghuirong
#huanghuirong1:
# user.absent
sudo_open:
cmd.run:
- name: "chattr -i /etc/sudoers"
- cwd: /
- user: root
sudo_adduser:
file.append:
- name: /etc/sudoers
- text:
- "huanghuirong ALL=(ALL) NOPASSWD: ALL"
- require:
- cmd: sudo_open
sudo_deluser:
file.comment:
- name: /etc/sudoers
- regex: ^huanghuirong1 ALL
- require:
- cmd: sudo_open
sudo_close:
cmd.run:
- name: "chattr +i /etc/sudoers"
- cwd: /
- user: root
- order: 1
- require:
- file: /etc/sudoers
[root@mod salt]# cat /srv/salt/files.sls
files:
file.managed:
- name: /tmp/t.txt
- source: salt://files/t.txt
- mode: 644
- owner: root
- group: root
[root@mod files]# ls /srv/salt/files/t.txt
/srv/salt/files/t.txt