forked from bloomberg/chef-bach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_chef_cookbooks.sh
executable file
·68 lines (52 loc) · 1.89 KB
/
setup_chef_cookbooks.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
#!/bin/bash -e
# Expected to be run in the root of the Chef Git repository (e.g. chef-bcpc)
set -x
if [[ -f ./proxy_setup.sh ]]; then
. ./proxy_setup.sh
fi
BOOTSTRAP_IP="${1-10.0.100.3}"
USER="${2-root}"
ENVIRONMENT="${3-Test-Laptop}"
# load binary_server_url and binary_server_host (usually the bootstrap)
load_binary_server_info "$ENVIRONMENT"
mkdir -p .chef
cat << EOF > .chef/knife.rb
require 'rubygems'
require 'ohai'
# Disable the Ohai password module which explodes on a Single-Sign-On-joined system
ohai.disabled_plugins = [ "passwd" ]
o = Ohai::System.new
o.all_plugins(['hostname','ipaddress'])
log_level :info
node_name o[:fqdn]
client_key "$(pwd)/.chef/#{o[:fqdn]}.pem"
validation_client_name 'chef-validator'
validation_key '/etc/chef-server/chef-validator.pem'
chef_server_url 'https://${BOOTSTRAP_IP}'
syntax_check_cache_path '$(pwd)/.chef/syntax_check_cache'
cookbook_path '$(pwd)/vendor/cookbooks'
ssl_verify_mode :verify_none
verify_api_cert false
knife[:vault_mode] = 'client'
File.umask(0007)
EOF
if [[ -n "$http_proxy" ]]; then
cat << EOF >> .chef/knife.rb
no_proxy_array = ["localhost", o[:ipaddress], o[:hostname], o[:fqdn], "${BOOTSTRAP_IP}", "${binary_server_host}", ENV['no_proxy']].compact
no_proxy_array.insert("*#{o[:domain]}") unless o[:domain].nil?
no_proxy_string = no_proxy_array.uniq * ","
ENV['no_proxy'] = no_proxy_string
http_proxy_string = "${http_proxy}"
ENV['http_proxy'] =
http_proxy_string.downcase.start_with?('http') ? http_proxy_string : nil
https_proxy_string = "${https_proxy}"
ENV['https_proxy'] =
https_proxy_string.downcase.start_with?('http') ? https_proxy_string : nil
http_proxy ENV['http_proxy']
https_proxy ENV['https_proxy']
no_proxy no_proxy_string
ENV['GIT_SSL_NO_VERIFY'] = 'true'
EOF
fi # end of [[ ! -f .chef/knife.rb ]]
mkdir -p ./vendor
/opt/chefdk/bin/berks vendor ./vendor/cookbooks