forked from bloomberg/chef-bach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_chef_bootstrap_node.sh
executable file
·37 lines (28 loc) · 1.3 KB
/
setup_chef_bootstrap_node.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
#!/bin/bash
# Parameters :
# $1 is the IP address of the bootstrap node
# $2 is the Chef environment name, default "Test-Laptop"
set -e
set -x
if [[ $# -ne 2 ]]; then
echo "Usage: `basename $0` IP-Address Chef-Environment" >> /dev/stderr
exit
fi
CHEF_SERVER=$1
CHEF_ENVIRONMENT=$2
# Assume we are running in the chef-bcpc directory
# Are we running under Vagrant? If so, jump through some extra hoops.
sudo chef-client -E "$CHEF_ENVIRONMENT" -c .chef/knife.rb
sudo chown $(whoami):root .chef/$(hostname -f).pem
sudo chmod 550 .chef/$(hostname -f).pem
admin_val=`knife client show $(hostname -f) -c .chef/knife.rb | grep ^admin: | sed "s/admin:[^a-z]*//"`
if [[ "$admin_val" != "true" ]]; then
# Make this client an admin user before proceeding.
echo -e "/\"admin\": false\ns/false/true\nw\nq\n" | EDITOR=ed sudo -E knife client edit `hostname -f` -c .chef/knife.rb -k /etc/chef-server/admin.pem -u admin
fi
knife node run_list add $(hostname -f) 'role[BCPC-Bootstrap]' -c .chef/knife.rb
sudo chef-client -c .chef/knife.rb
# Create a symlink in /etc/chef/client.d/ to knife.rb so that one can run chef-client
# on the bootstrap node without having to specify -c .chef/knife.rb later. This will
# make sure that the chef-client service runs without issues.
sudo ln -s $(pwd)/.chef/knife.rb /etc/chef/client.d/knife.rb