-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux_salt_bootstrap_2017_7_2.sh
57 lines (47 loc) · 1.7 KB
/
linux_salt_bootstrap_2017_7_2.sh
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
#!/usr/bin/env bash
set -e
set -u
readonly MASTER_CONFIG='file_roots:, base:, - /srv/salt, - /srv/formulas, - /srv/salt/roles,pillar_roots:, base:, - /srv/pillar, dev:, - /srv/pillar/dev, production:, - /srv/pillar/production'
function install_salt_repo() {
rpm --import https://archive.repo.saltstack.com/yum/redhat/7/x86_64/archive/2017.7.2/SALTSTACK-GPG-KEY.pub
local repofile='/etc/yum.repos.d/saltstack.repo'
echo '[saltstack-repo]' > $repofile
echo 'name=SaltStack repo for RHEL/CentOS $releasever' >> $repofile
echo 'baseurl=https://archive.repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/2017.7.2' >> $repofile
echo 'enabled=1' >> $repofile
echo 'gpgcheck=1' >> $repofile
echo 'gpgkey=https://archive.repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/2017.7.2/$releaseverSALTSTACK-GPG-KEY.pub' >> $repofile
yum clean all
}
function install_salt_master() {
install_salt_repo
yum update -y
yum install salt-master salt-minion -y
echo -e "$MASTER_CONFIG" | tr ',' '\n' > /etc/salt/master
for service in salt-master salt-minion; do
systemctl enable $service.service
systemctl start $service.service
done
}
function install_salt_minion() {
local master=$1
install_salt_repo
yum install salt-minion -y
echo "master: $master" > /etc/salt/minion
systemctl enable salt-minion.service
systemctl start salt-minion.service
salt-call saltutil.sync_grains
salt-call saltutil.refresh_pillar
echo "startup_states: highstate" >> /etc/salt/minion
salt-call state.highstate
yum update -y
salt-call system.reboot 5
}
main() {
if [[ $1 == 'master' ]]; then
install_salt_master
else
install_salt_minion $2
fi
}
main $@