-
Notifications
You must be signed in to change notification settings - Fork 0
/
boostrap.sh
executable file
·88 lines (60 loc) · 1.8 KB
/
boostrap.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
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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
chef_version='12.15.8'
rpm_package="chef-server-core-$chef_version-1.el7.x86_64.rpm"
rpm_url="https://packages.chef.io/files/stable/chef-server/$chef_version/el/7/$rpm_package"
# 0 - fetch Chef server RPM
[ -f "./$rpm_package" ] || curl -LO "$rpm_url"
# 1 - setup virtual machines
vagrant status | grep -q running || vagrant up
# 2 - obtain private key for "admin" user
vagrant ssh-config > ./.ssh_config
ssh -F ./.ssh_config chef-server cat admin.pem > ./.chef/admin.pem
# 3 - obtain TLS certificates from Chef server
rm -rfv .chef/trusted_certs && knife ssl fetch && knife ssl check
# 4 - fetch and upload the 'chef-client' cookbook and it's dependencies to
# chef-server
cat > ./Berksfile <<-'EOF'
source 'https://supermarket.chef.io'
cookbook 'chef-client'
EOF
berks install
SSL_CERT_FILE='./.chef/trusted_certs/chef-server.crt' berks upload
# 5 - create a 'base' role with 'chef-client' cookbook recipes in it's run_list
mkdir -pv ./roles
cat > ./roles/base.json <<-'EOF'
{
"name": "base",
"description": "Base role",
"json_class": "Chef::Role",
"default_attributes": {
"chef_client": {
"interval": 300,
"splay": 60
}
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
"recipe[chef-client::default]",
"recipe[chef-client::delete_validation]"
],
"env_run_lists": {
}
}
EOF
# 6 - upload 'base' role to chef-server
knife role from file ./roles/base.json
# 7 - bootstrap all the nodes
for node in node-1 node-2 node-3; do
knife bootstrap "$node" \
--ssh-user vagrant \
--sudo \
--identity-file "./.vagrant/machines/$node/libvirt/private_key" \
--run-list 'role[base]' \
--node-name "$node"
done
# 8 - display status
knife status role:base --run-list