knife-server 0.3.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +14 -4
- data/CHANGELOG.md +50 -9
- data/Gemfile +3 -0
- data/README.md +112 -40
- data/knife-server.gemspec +2 -1
- data/lib/chef/knife/bootstrap/_common.sh +24 -0
- data/lib/chef/knife/bootstrap/_omnibus.sh +117 -0
- data/lib/chef/knife/bootstrap/_platform_and_version.sh +115 -0
- data/lib/chef/knife/bootstrap/_set_hostname.sh +60 -0
- data/lib/chef/knife/bootstrap/auto.sh +116 -0
- data/lib/chef/knife/bootstrap/{chef-server-debian.erb → chef10/debian.erb} +22 -40
- data/lib/chef/knife/bootstrap/chef10/rhel.erb +185 -0
- data/lib/chef/knife/bootstrap/chef11/omnibus.erb +64 -0
- data/lib/chef/knife/bootstrap/chef11/rhel.erb +142 -0
- data/lib/chef/knife/server_bootstrap_base.rb +89 -41
- data/lib/chef/knife/server_bootstrap_ec2.rb +46 -74
- data/lib/chef/knife/server_bootstrap_standalone.rb +25 -19
- data/lib/knife/server/credentials.rb +44 -7
- data/lib/knife/server/ssh.rb +57 -1
- data/lib/knife/server/version.rb +1 -1
- data/spec/chef/knife/server_bootstrap_ec2_spec.rb +28 -5
- data/spec/chef/knife/server_bootstrap_standalone_spec.rb +66 -5
- data/spec/knife/server/credientials_spec.rb +34 -0
- metadata +14 -6
@@ -0,0 +1,185 @@
|
|
1
|
+
bash -c '
|
2
|
+
<%= %{export http_proxy="#{knife_config[:bootstrap_proxy]}"} if knife_config[:bootstrap_proxy] -%>
|
3
|
+
|
4
|
+
export hostname="<%= @config[:chef_node_name] %>"
|
5
|
+
export webui_password="<%= ENV['WEBUI_PASSWORD'] %>"
|
6
|
+
export amqp_password="<%= ENV['AMQP_PASSWORD'] %>"
|
7
|
+
export chef_version="<%= Chef::VERSION %>"
|
8
|
+
|
9
|
+
set -e
|
10
|
+
|
11
|
+
setup() {
|
12
|
+
if grep -qi "Red Hat" /etc/redhat-release
|
13
|
+
then
|
14
|
+
platform="redhat"
|
15
|
+
else
|
16
|
+
platform=$(cat /etc/redhat-release | cut -d" " -f1 | tr [[:upper:]] [[:lower:]])
|
17
|
+
fi
|
18
|
+
|
19
|
+
# throttle selinux, people can set it back up themselves if they want.
|
20
|
+
(setenforce Permissive || exit 0)
|
21
|
+
if [ -f /etc/selinux/config ]
|
22
|
+
then
|
23
|
+
cd /etc/selinux
|
24
|
+
sed -i.bak 's/SELINUX=enforcing/SELINUX=permissive/g' config
|
25
|
+
cd $OLDPWD
|
26
|
+
fi
|
27
|
+
|
28
|
+
yum install ruby rubygems ruby-devel -y
|
29
|
+
yum install readline-devel zlib-devel libyaml-devel openssl-devel \
|
30
|
+
make autoconf automake gcc tar libstdc++-devel gcc-c++ -y
|
31
|
+
|
32
|
+
/usr/bin/gem install rubygems-update -v 1.8.25
|
33
|
+
/usr/bin/update_rubygems
|
34
|
+
}
|
35
|
+
|
36
|
+
set_hostname_for_centos() {
|
37
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
38
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
39
|
+
return
|
40
|
+
fi
|
41
|
+
|
42
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
43
|
+
local hostnames="${hostname} ${host_first}"
|
44
|
+
|
45
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
46
|
+
|
47
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
48
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
49
|
+
else
|
50
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
51
|
+
fi
|
52
|
+
/bin/hostname ${hostname}
|
53
|
+
}
|
54
|
+
|
55
|
+
set_hostname_for_redhat() {
|
56
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
57
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
58
|
+
return
|
59
|
+
fi
|
60
|
+
|
61
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
62
|
+
local hostnames="${hostname} ${host_first}"
|
63
|
+
|
64
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
65
|
+
|
66
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
67
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
68
|
+
else
|
69
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
70
|
+
fi
|
71
|
+
/bin/hostname ${hostname}
|
72
|
+
}
|
73
|
+
|
74
|
+
set_hostname_for_amazon() {
|
75
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
76
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
77
|
+
return
|
78
|
+
fi
|
79
|
+
|
80
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
81
|
+
local hostnames="${hostname} ${host_first}"
|
82
|
+
|
83
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
84
|
+
|
85
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
86
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
87
|
+
else
|
88
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
89
|
+
fi
|
90
|
+
/bin/hostname ${hostname}
|
91
|
+
}
|
92
|
+
|
93
|
+
set_hostname_for_scientific() {
|
94
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
95
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
96
|
+
return
|
97
|
+
fi
|
98
|
+
|
99
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
100
|
+
local hostnames="${hostname} ${host_first}"
|
101
|
+
|
102
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
103
|
+
|
104
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
105
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
106
|
+
else
|
107
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
108
|
+
fi
|
109
|
+
/bin/hostname ${hostname}
|
110
|
+
}
|
111
|
+
|
112
|
+
set_hostname_for_enterpriseenterprise() {
|
113
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
114
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
115
|
+
return
|
116
|
+
fi
|
117
|
+
|
118
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
119
|
+
local hostnames="${hostname} ${host_first}"
|
120
|
+
|
121
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
122
|
+
|
123
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
124
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
125
|
+
else
|
126
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
127
|
+
fi
|
128
|
+
/bin/hostname ${hostname}
|
129
|
+
}
|
130
|
+
|
131
|
+
config_chef_solo() {
|
132
|
+
local tmp_solo="$1"
|
133
|
+
|
134
|
+
mkdir -p $tmp_solo
|
135
|
+
cat <<SOLO_RB > $tmp_solo/solo.rb
|
136
|
+
file_cache_path "$tmp_solo"
|
137
|
+
cookbook_path "$tmp_solo/cookbooks"
|
138
|
+
SOLO_RB
|
139
|
+
|
140
|
+
cat<<BOOTSTRAP_JSON > $tmp_solo/bootstrap.json
|
141
|
+
{
|
142
|
+
"chef_server": {
|
143
|
+
"webui_enabled" : true,
|
144
|
+
"ssl_req" : "/C=CA/ST=Several/L=Locality/O=Example/OU=Operations/CN=${hostname}/emailAddress=root@${hostname}"
|
145
|
+
},
|
146
|
+
"run_list": [ "recipe[chef-server::rubygems-install]", "recipe[chef-server::apache-proxy]" ]
|
147
|
+
}
|
148
|
+
BOOTSTRAP_JSON
|
149
|
+
}
|
150
|
+
|
151
|
+
install_chef_server() {
|
152
|
+
# hack, ensure net-ssh 2.2.2 and net-ssh-multi 1.1.0 is installed before
|
153
|
+
# installing chef, otherwise rubygems will explode trying to run chef
|
154
|
+
|
155
|
+
gem install net-ssh -v 2.2.2 --no-ri --no-rdoc
|
156
|
+
gem install net-ssh-gateway -v 1.1.0 --no-ri --no-rdoc
|
157
|
+
gem install net-ssh-multi -v 1.1.0 --no-ri --no-rdoc
|
158
|
+
gem install chef -v $chef_version --no-ri --no-rdoc
|
159
|
+
|
160
|
+
local tmp_solo=/tmp/chef-solo
|
161
|
+
|
162
|
+
config_chef_solo $tmp_solo
|
163
|
+
|
164
|
+
chef-solo -c $tmp_solo/solo.rb -j $tmp_solo/bootstrap.json \
|
165
|
+
-r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz
|
166
|
+
|
167
|
+
rm -rf $tmp_solo
|
168
|
+
}
|
169
|
+
|
170
|
+
configure_firewall() {
|
171
|
+
# chef-server-api
|
172
|
+
/usr/sbin/lokkit -p 4000:tcp
|
173
|
+
# chef-server-webui
|
174
|
+
/usr/sbin/lokkit -p 4040:tcp
|
175
|
+
# ssl proxy to chef-server-api
|
176
|
+
/usr/sbin/lokkit -p 443:tcp
|
177
|
+
}
|
178
|
+
|
179
|
+
setup
|
180
|
+
set_hostname_for_${platform}
|
181
|
+
install_chef_server
|
182
|
+
configure_firewall
|
183
|
+
|
184
|
+
printf -- "-----> Bootstraping Chef Server on ${hostname} is complete.\n"
|
185
|
+
'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
bash -c '
|
2
|
+
<%
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
def render(partial)
|
6
|
+
partial_path = Gem.find_files(File.join(
|
7
|
+
%W{chef knife bootstrap _#{partial}}
|
8
|
+
)).first
|
9
|
+
raise ArgumentError, "Partial _#{partial} not found" if partial_path.nil?
|
10
|
+
|
11
|
+
ERB.new(IO.read(partial_path)).result(binding)
|
12
|
+
end
|
13
|
+
-%>
|
14
|
+
set -e
|
15
|
+
<%= %{set -x} if @chef_config[:knife][:log_level] == :debug -%>
|
16
|
+
|
17
|
+
<%=
|
18
|
+
if knife_config[:bootstrap_proxy]
|
19
|
+
%{export http_proxy="#{knife_config[:bootstrap_proxy]}"}
|
20
|
+
end
|
21
|
+
-%>
|
22
|
+
export hostname="<%= @config[:chef_node_name] %>"
|
23
|
+
export version="<%= @config[:bootstrap_version] %>"
|
24
|
+
export prerelease="<%= @config[:prerelease] == true %>"
|
25
|
+
export webui_enable="<%= @chef_config[:knife][:webui_enable] == true %>"
|
26
|
+
export webui_password="<%= ENV['WEBUI_PASSWORD'] %>"
|
27
|
+
export amqp_password="<%= ENV['AMQP_PASSWORD'] %>"
|
28
|
+
|
29
|
+
<%= render "common.sh" %>
|
30
|
+
|
31
|
+
<%= render "platform_and_version.sh" %>
|
32
|
+
|
33
|
+
<%= render "set_hostname.sh" %>
|
34
|
+
|
35
|
+
<%= render "omnibus.sh" %>
|
36
|
+
|
37
|
+
#
|
38
|
+
# Chef Server Omnibus installation
|
39
|
+
#
|
40
|
+
|
41
|
+
# Set filename
|
42
|
+
case $platform in
|
43
|
+
"ubuntu") deb_filename ;;
|
44
|
+
"debian") deb_filename ;;
|
45
|
+
"el") rpm_filename ;;
|
46
|
+
"suse") rpm_filename ;;
|
47
|
+
"sles") rpm_filename ;;
|
48
|
+
"fedora") rpm_filename ;;
|
49
|
+
esac
|
50
|
+
|
51
|
+
# Set tmp_dir
|
52
|
+
tmp_dir=$(mktemp -d -t tmp.XXXXXXXX || echo "/tmp")
|
53
|
+
|
54
|
+
set_hostname_for_${platform}
|
55
|
+
download_package
|
56
|
+
install_package
|
57
|
+
prepare_chef_server_rb
|
58
|
+
symlink_binaries
|
59
|
+
reconfigure_chef_server
|
60
|
+
test_chef_server
|
61
|
+
configure_firewall
|
62
|
+
|
63
|
+
banner "Bootstraping Chef Server on ${hostname} is complete."
|
64
|
+
'
|
@@ -0,0 +1,142 @@
|
|
1
|
+
bash -c '
|
2
|
+
<%= %{export http_proxy="#{knife_config[:bootstrap_proxy]}"} if knife_config[:bootstrap_proxy] -%>
|
3
|
+
|
4
|
+
export hostname="<%= @config[:chef_node_name] %>"
|
5
|
+
export webui_password="<%= ENV['WEBUI_PASSWORD'] %>"
|
6
|
+
export amqp_password="<%= ENV['AMQP_PASSWORD'] %>"
|
7
|
+
export chef_version="<%= Chef::VERSION %>"
|
8
|
+
|
9
|
+
set -e
|
10
|
+
|
11
|
+
setup() {
|
12
|
+
if grep -qi "Red Hat" /etc/redhat-release
|
13
|
+
then
|
14
|
+
platform="redhat"
|
15
|
+
else
|
16
|
+
platform=$(cat /etc/redhat-release | cut -d" " -f1 | tr [[:upper:]] [[:lower:]])
|
17
|
+
fi
|
18
|
+
|
19
|
+
# throttle selinux, people can set it back up themselves if they want.
|
20
|
+
(setenforce Permissive || exit 0)
|
21
|
+
if [ -f /etc/selinux/config ]
|
22
|
+
then
|
23
|
+
cd /etc/selinux
|
24
|
+
sed -i.bak 's/SELINUX=enforcing/SELINUX=permissive/g' config
|
25
|
+
cd $OLDPWD
|
26
|
+
fi
|
27
|
+
}
|
28
|
+
|
29
|
+
set_hostname_for_platform() {
|
30
|
+
if hostname | grep -q "$hostname" > /dev/null ; then
|
31
|
+
printf -- "-----> Hostname is correct, so skipping...\n"
|
32
|
+
return
|
33
|
+
fi
|
34
|
+
|
35
|
+
local host_first="$(echo $hostname | cut -d . -f 1)"
|
36
|
+
local hostnames="${hostname} ${host_first}"
|
37
|
+
|
38
|
+
sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
|
39
|
+
|
40
|
+
if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
|
41
|
+
sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
|
42
|
+
else
|
43
|
+
sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" /etc/hosts
|
44
|
+
fi
|
45
|
+
/bin/hostname ${hostname}
|
46
|
+
}
|
47
|
+
|
48
|
+
set_hostname_for_centos() {
|
49
|
+
set_hostname_for_platform
|
50
|
+
}
|
51
|
+
|
52
|
+
set_hostname_for_redhat() {
|
53
|
+
set_hostname_for_platform
|
54
|
+
}
|
55
|
+
|
56
|
+
set_hostname_for_amazon() {
|
57
|
+
set_hostname_for_platform
|
58
|
+
}
|
59
|
+
|
60
|
+
set_hostname_for_scientific() {
|
61
|
+
set_hostname_for_platform
|
62
|
+
}
|
63
|
+
|
64
|
+
set_hostname_for_enterpriseenterprise() {
|
65
|
+
set_hostname_for_platform
|
66
|
+
}
|
67
|
+
|
68
|
+
install_omnibus_chef() {
|
69
|
+
yum install -y curl bash
|
70
|
+
curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v "${chef_version}"
|
71
|
+
}
|
72
|
+
|
73
|
+
download_cookbook() {
|
74
|
+
local server_ckbk_dir="$1/chef-server"
|
75
|
+
local url="https://github.com/opscode-cookbooks/chef-server/archive/master.tar.gz"
|
76
|
+
|
77
|
+
mkdir -p "$server_ckbk_dir"
|
78
|
+
(cd "$server_ckbk_dir" && \
|
79
|
+
curl -sL "$url" | gunzip -c - | tar xf - --strip-components=1)
|
80
|
+
}
|
81
|
+
|
82
|
+
config_chef_solo() {
|
83
|
+
local tmp_solo="$1"
|
84
|
+
|
85
|
+
mkdir -p $tmp_solo/cookbooks
|
86
|
+
cat > $tmp_solo/solo.rb <<SOLO_RB
|
87
|
+
file_cache_path "$tmp_solo"
|
88
|
+
cookbook_path "$tmp_solo/cookbooks"
|
89
|
+
SOLO_RB
|
90
|
+
|
91
|
+
cat <<BOOTSTRAP_JSON > $tmp_solo/bootstrap.json
|
92
|
+
{
|
93
|
+
"chef-server" : {
|
94
|
+
"prereleases" : true,
|
95
|
+
"chef-server-webui" : {
|
96
|
+
"web_ui_admin_default_password" : "$webui_password"
|
97
|
+
},
|
98
|
+
"rabbitmq" : {
|
99
|
+
"password" : "$amqp_password"
|
100
|
+
}
|
101
|
+
},
|
102
|
+
"run_list" : [ "recipe[chef-server]" ]
|
103
|
+
}
|
104
|
+
BOOTSTRAP_JSON
|
105
|
+
|
106
|
+
download_cookbook $tmp_solo/cookbooks
|
107
|
+
}
|
108
|
+
|
109
|
+
run_chef_solo() {
|
110
|
+
local tmp_solo=/tmp/chef-solo
|
111
|
+
|
112
|
+
config_chef_solo $tmp_solo
|
113
|
+
chef-solo -c $tmp_solo/solo.rb -j $tmp_solo/bootstrap.json
|
114
|
+
rm -rf $tmp_solo
|
115
|
+
}
|
116
|
+
|
117
|
+
cleanup() {
|
118
|
+
for bin in chef-client chef-solo chef-shell knife ohai shef ; do
|
119
|
+
ln -snf /opt/chef-server/bin/$bin /usr/bin/$bin
|
120
|
+
done ; unset bin
|
121
|
+
|
122
|
+
rm -rf /opt/chef
|
123
|
+
}
|
124
|
+
|
125
|
+
configure_firewall() {
|
126
|
+
# chef-server-api
|
127
|
+
/usr/sbin/lokkit -p 4000:tcp
|
128
|
+
# chef-server-webui
|
129
|
+
/usr/sbin/lokkit -p 4040:tcp
|
130
|
+
# ssl proxy to chef-server-api
|
131
|
+
/usr/sbin/lokkit -p 443:tcp
|
132
|
+
}
|
133
|
+
|
134
|
+
setup
|
135
|
+
set_hostname_for_${platform}
|
136
|
+
install_omnibus_chef
|
137
|
+
run_chef_solo
|
138
|
+
configure_firewall
|
139
|
+
cleanup
|
140
|
+
|
141
|
+
echo "-----> Bootstraping Chef Server on ${hostname} is complete."
|
142
|
+
'
|
@@ -30,54 +30,32 @@ class Chef
|
|
30
30
|
require 'net/ssh'
|
31
31
|
end
|
32
32
|
|
33
|
-
option :chef_node_name,
|
34
|
-
:short => "-N NAME",
|
35
|
-
:long => "--node-name NAME",
|
36
|
-
:description => "The name of your new Chef Server"
|
37
|
-
|
38
33
|
option :platform,
|
39
34
|
:short => "-P PLATFORM",
|
40
35
|
:long => "--platform PLATFORM",
|
41
|
-
:description => "The platform type that will be bootstrapped (
|
42
|
-
:default => "
|
43
|
-
|
44
|
-
option :ssh_user,
|
45
|
-
:short => "-x USERNAME",
|
46
|
-
:long => "--ssh-user USERNAME",
|
47
|
-
:description => "The ssh username",
|
48
|
-
:default => "root"
|
49
|
-
|
50
|
-
option :ssh_port,
|
51
|
-
:short => "-p PORT",
|
52
|
-
:long => "--ssh-port PORT",
|
53
|
-
:description => "The ssh port",
|
54
|
-
:default => "22",
|
55
|
-
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
56
|
-
|
57
|
-
option :identity_file,
|
58
|
-
:short => "-i IDENTITY_FILE",
|
59
|
-
:long => "--identity-file IDENTITY_FILE",
|
60
|
-
:description => "The SSH identity file used for authentication"
|
36
|
+
:description => "The platform type that will be bootstrapped (omnibus)",
|
37
|
+
:default => "omnibus"
|
61
38
|
|
62
|
-
option :
|
63
|
-
:
|
64
|
-
:
|
39
|
+
option :distro,
|
40
|
+
:short => "-d DISTRO",
|
41
|
+
:long => "--distro DISTRO",
|
42
|
+
:description => "Bootstrap a distro using a template; default is 'chef11/omnibus'"
|
65
43
|
|
66
44
|
option :bootstrap_version,
|
67
45
|
:long => "--bootstrap-version VERSION",
|
68
|
-
:description => "The version of Chef to install",
|
69
|
-
:proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
46
|
+
:description => "The version of Chef Server to install, default is latest release",
|
47
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v },
|
48
|
+
:default => nil
|
70
49
|
|
71
|
-
option :
|
72
|
-
:long => "--
|
73
|
-
:description => "
|
74
|
-
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
|
75
|
-
:default => false
|
50
|
+
option :prerelease,
|
51
|
+
:long => "--prerelease",
|
52
|
+
:description => "Install a pre-release version of Chef Server"
|
76
53
|
|
77
|
-
option :
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
54
|
+
option :webui_enable,
|
55
|
+
:long => "--[no-]webui-enable",
|
56
|
+
:description => "Whether or not to enable the webui, default is false",
|
57
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:webui_enable] = v },
|
58
|
+
:default => false
|
81
59
|
|
82
60
|
option :webui_password,
|
83
61
|
:long => "--webui-password SECRET",
|
@@ -88,6 +66,13 @@ class Chef
|
|
88
66
|
:long => "--amqp-password SECRET",
|
89
67
|
:description => "Initial password for AMQP, default is 'chefchef'",
|
90
68
|
:default => "chefchef"
|
69
|
+
|
70
|
+
option :log_level,
|
71
|
+
:short => "-l LEVEL",
|
72
|
+
:long => "--log-level LEVEL",
|
73
|
+
:description => "Set the log level (debug, info, warn, error, fatal)",
|
74
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:log_level] = v.to_sym },
|
75
|
+
:default => :error
|
91
76
|
end
|
92
77
|
end
|
93
78
|
|
@@ -106,13 +91,76 @@ class Chef
|
|
106
91
|
ui.msg(credentials_client.create_root_client)
|
107
92
|
end
|
108
93
|
|
94
|
+
def bootstrap_auto?
|
95
|
+
config_val(:platform) == "auto"
|
96
|
+
end
|
97
|
+
|
98
|
+
def distro_auto_map(platform, platform_version)
|
99
|
+
# NOTE this logic is shared with chef/knife/bootstrap/auto.sh, which is
|
100
|
+
# run on the server side.
|
101
|
+
# XXX we don't actually use the platform_version stuff, just included
|
102
|
+
# because we get it for free in the script and it might prove
|
103
|
+
# useful later.
|
104
|
+
# XXX might be better to have chef/ohai's platform_family? do this for
|
105
|
+
# us in the long term.
|
106
|
+
|
107
|
+
normal = case platform
|
108
|
+
when "debian", "ubuntu"
|
109
|
+
"debian"
|
110
|
+
when "el", "redhat"
|
111
|
+
"rhel"
|
112
|
+
when /^solaris/
|
113
|
+
"solaris"
|
114
|
+
when "sles", "suse"
|
115
|
+
"suse"
|
116
|
+
end
|
117
|
+
|
118
|
+
return construct_distro(normal)
|
119
|
+
end
|
120
|
+
|
121
|
+
def construct_distro(platform)
|
122
|
+
"chef#{chef_server_major_version}/#{platform}"
|
123
|
+
end
|
124
|
+
|
125
|
+
def chef_server_major_version
|
126
|
+
version = config_val(:bootstrap_version)
|
127
|
+
|
128
|
+
version.nil? ? 11 : version.split(".").first.to_i
|
129
|
+
end
|
130
|
+
|
109
131
|
def bootstrap_distro
|
110
|
-
|
132
|
+
return config_val(:distro) if config_val(:distro)
|
133
|
+
return determine_platform if config_val(:platform) == "auto"
|
134
|
+
return construct_distro(config_val(:platform))
|
111
135
|
end
|
112
136
|
|
113
137
|
def credentials_client
|
138
|
+
opts = {}
|
139
|
+
opts[:omnibus] = true if chef_server_major_version > 10
|
114
140
|
@credentials_client ||= ::Knife::Server::Credentials.new(
|
115
|
-
ssh_connection, Chef::Config[:validation_key])
|
141
|
+
ssh_connection, Chef::Config[:validation_key], opts)
|
142
|
+
end
|
143
|
+
|
144
|
+
def determine_platform
|
145
|
+
return nil unless bootstrap_auto?
|
146
|
+
|
147
|
+
script = File.binread(File.expand_path("bootstrap/auto.sh", File.dirname(__FILE__)))
|
148
|
+
|
149
|
+
# result is expected to be two lines, first being the platform name,
|
150
|
+
# second being the platform version.
|
151
|
+
result, exit_status = ssh_connection.run_script(script)
|
152
|
+
|
153
|
+
if exit_status != 0 or !result or result.strip.empty?
|
154
|
+
raise "Could not determine the OS running the target for the chef server. Please specify --platform."
|
155
|
+
end
|
156
|
+
|
157
|
+
return distro_auto_map(*result.split(/\n/).compact[0..1])
|
158
|
+
end
|
159
|
+
|
160
|
+
def config_val(key)
|
161
|
+
key = key.to_sym
|
162
|
+
default_value = options[key] && options[key][:default]
|
163
|
+
config.fetch(key, Chef::Config[:knife].fetch(key, default_value))
|
116
164
|
end
|
117
165
|
end
|
118
166
|
end
|