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.
@@ -0,0 +1,117 @@
1
+ #
2
+ # Partial: _omnibus
3
+ #
4
+ # Functions to install Chef Server from an Ombibus package
5
+ #
6
+
7
+ package_url() {
8
+ local base="http://www.opscode.com/chef/download-server"
9
+ if [ -n "$version" ] ; then
10
+ local v="&v=${version}"
11
+ fi
12
+
13
+ echo "${base}?p=${platform}&pv=${platform_version}&m=${machine}&prerelease=${prerelease}${v}"
14
+ }
15
+
16
+ # Set the filename for a deb, based on version and machine
17
+ deb_filename() {
18
+ filetype="deb"
19
+ if [ $machine = "x86_64" ];
20
+ then
21
+ filename="chef_${version}_amd64.deb"
22
+ else
23
+ filename="chef_${version}_i386.deb"
24
+ fi
25
+ }
26
+
27
+ # Set the filename for an rpm, based on version and machine
28
+ rpm_filename() {
29
+ filetype="rpm"
30
+ filename="chef-${version}.${machine}.rpm"
31
+ }
32
+
33
+ download_package() {
34
+ if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
35
+ info "Chef Server detected in /opt/chef-server, skipping download"
36
+ return 0
37
+ fi
38
+
39
+ local url="$(package_url)"
40
+
41
+ banner "Downloading Chef Server package from $url to $tmp_dir/$filename"
42
+ if exists wget;
43
+ then
44
+ wget -O "$tmp_dir/$filename" $url 2>/tmp/stderr
45
+ elif exists curl;
46
+ then
47
+ curl -L $url > "$tmp_dir/$filename"
48
+ else
49
+ warn "Cannot find wget or curl - cannot install Chef Server!"
50
+ exit 5
51
+ fi
52
+ info "Download complete"
53
+ }
54
+
55
+ install_package() {
56
+ if [ -f "/opt/chef-server/bin/chef-server-ctl" ] ; then
57
+ info "Chef Server detected in /opt/chef-server, skipping installation"
58
+ return 0
59
+ fi
60
+
61
+ banner "Installing Chef Server $version"
62
+ case "$filetype" in
63
+ "rpm") rpm -Uvh "$tmp_dir/$filename" ;;
64
+ "deb") dpkg -i "$tmp_dir/$filename" ;;
65
+ esac
66
+
67
+ if [ "$tmp_dir" != "/tmp" ];
68
+ then
69
+ rm -r "$tmp_dir"
70
+ fi
71
+ banner "Package installed"
72
+ }
73
+
74
+ prepare_chef_server_rb() {
75
+ local config_file="/etc/chef-server/chef-server.rb"
76
+
77
+ banner "Creating $config_file"
78
+ mkdir -p "$(dirname $config_file)"
79
+ cat <<CHEF_SERVER > "$config_file"
80
+ topology "standalone"
81
+
82
+ api_fqdn "$hostname"
83
+
84
+ rabbitmq["password"] = "$amqp_password"
85
+
86
+ chef_server_webui["enable"] = $webui_enable
87
+ chef_server_webui["web_ui_admin_default_password"] = "$webui_password"
88
+ CHEF_SERVER
89
+ chmod 0600 "$config_file"
90
+ info "Config file created"
91
+ }
92
+
93
+ symlink_binaries() {
94
+ for bin in chef-client chef-solo chef-apply knife ohai ; do
95
+ banner "Updating /usr/bin/$bin symlink"
96
+ ln -snf /opt/chef-server/embedded/bin/$bin /usr/bin/$bin
97
+ done ; unset bin
98
+ }
99
+
100
+ reconfigure_chef_server() {
101
+ banner "Reconfiguring Chef Server"
102
+ chef-server-ctl reconfigure
103
+ info "Server reconfigured"
104
+ }
105
+
106
+ test_chef_server() {
107
+ banner "Testing Chef Server"
108
+ chef-server-ctl test
109
+ info "Pedant suite finished"
110
+ }
111
+
112
+ configure_firewall() {
113
+ if [ -x "/usr/sbin/lokkit" ] ; then
114
+ banner "Opening TCP port 443"
115
+ /usr/sbin/lokkit -p 443:tcp
116
+ fi
117
+ }
@@ -0,0 +1,115 @@
1
+ #
2
+ # Partial: _platform_and_version.sh
3
+ #
4
+ # The code has been extracted from the Chef client Omnibus installer script
5
+ # located at: https://www.opscode.com/chef/install.sh
6
+ #
7
+
8
+ machine=$(echo -e `uname -m`)
9
+
10
+ # Retrieve Platform and Platform Version
11
+ if [ -f "/etc/lsb-release" ];
12
+ then
13
+ platform=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr "[A-Z]" "[a-z]")
14
+ platform_version=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2)
15
+ elif [ -f "/etc/debian_version" ];
16
+ then
17
+ platform="debian"
18
+ platform_version=$(echo -e `cat /etc/debian_version`)
19
+ elif [ -f "/etc/redhat-release" ];
20
+ then
21
+ platform=$(sed "s/^\(.\+\) release.*/\1/" /etc/redhat-release | tr "[A-Z]" "[a-z]")
22
+ platform_version=$(sed "s/^.\+ release \([.0-9]\+\).*/\1/" /etc/redhat-release)
23
+
24
+ # If /etc/redhat-release exists, we act like RHEL by default
25
+ if [ "$platform" = "fedora" ];
26
+ then
27
+ # Change platform version for use below.
28
+ platform_version="6.0"
29
+ fi
30
+ platform="el"
31
+ elif [ -f "/etc/system-release" ];
32
+ then
33
+ platform=$(sed "s/^\(.\+\) release.\+/\1/" /etc/system-release | tr "[A-Z]" "[a-z]")
34
+ platform_version=$(sed "s/^.\+ release \([.0-9]\+\).*/\1/" /etc/system-release | tr "[A-Z]" "[a-z]")
35
+ # amazon is built off of fedora, so act like RHEL
36
+ if [ "$platform" = "amazon linux ami" ];
37
+ then
38
+ platform="el"
39
+ platform_version="6.0"
40
+ fi
41
+ # Apple OS X
42
+ elif [ -f "/usr/bin/sw_vers" ];
43
+ then
44
+ platform="mac_os_x"
45
+ # Matching the tab-space with sed is error-prone
46
+ platform_version=$(sw_vers | awk "/^ProductVersion:/ { print \$2 }")
47
+
48
+ major_version=$(echo $platform_version | cut -d. -f1,2)
49
+ case $major_version in
50
+ "10.6") platform_version="10.6" ;;
51
+ "10.7") platform_version="10.7" ;;
52
+ "10.8") platform_version="10.7" ;;
53
+ *) echo "No builds for platform: $major_version"
54
+ report_bug
55
+ exit 1
56
+ ;;
57
+ esac
58
+
59
+ # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
60
+ x86_64=$(sysctl -n hw.optional.x86_64)
61
+ if [ $x86_64 -eq 1 ]; then
62
+ machine="x86_64"
63
+ fi
64
+ elif [ -f "/etc/release" ];
65
+ then
66
+ platform="solaris2"
67
+ machine=$(/usr/bin/uname -p)
68
+ platform_version=$(/usr/bin/uname -r)
69
+ elif [ -f "/etc/SuSE-release" ];
70
+ then
71
+ if grep -q "Enterprise" /etc/SuSE-release;
72
+ then
73
+ platform="sles"
74
+ platform_version=$(awk "/^VERSION/ {V = \$3}; /^PATCHLEVEL/ {P = \$3}; END {print V "." P}" /etc/SuSE-release)
75
+ else
76
+ platform="suse"
77
+ platform_version=$(awk "/^VERSION =/ { print \$3 }" /etc/SuSE-release)
78
+ fi
79
+ fi
80
+
81
+ if [ "x$platform" = "x" ];
82
+ then
83
+ echo "Unable to determine platform version!"
84
+ report_bug
85
+ exit 1
86
+ fi
87
+
88
+ # Mangle $platform_version to pull the correct build
89
+ # for various platforms
90
+ major_version=$(echo $platform_version | cut -d. -f1)
91
+ case $platform in
92
+ "el")
93
+ case $major_version in
94
+ "5") platform_version="5" ;;
95
+ "6") platform_version="6" ;;
96
+ esac
97
+ ;;
98
+ "debian")
99
+ case $major_version in
100
+ "5") platform_version="6";;
101
+ "6") platform_version="6";;
102
+ esac
103
+ ;;
104
+ esac
105
+
106
+ if [ "x$platform_version" = "x" ];
107
+ then
108
+ echo "Unable to determine platform version!"
109
+ report_bug
110
+ exit 1
111
+ fi
112
+
113
+ export machine
114
+ export platform
115
+ export platform_version
@@ -0,0 +1,60 @@
1
+ #
2
+ # Partial: _set_hostname
3
+ #
4
+ # Functions to set a fully qualified hostname (FQDN) for the Chef Server on
5
+ # various platforms
6
+ #
7
+
8
+ set_hostname_for_ubuntu() {
9
+ if hostname | grep -q "$hostname" >/dev/null ; then
10
+ info "Hostname is correct, so skipping..."
11
+ return
12
+ fi
13
+
14
+ local host_first="$(echo $hostname | cut -d . -f 1)"
15
+ local hostnames="${hostname} ${host_first}"
16
+
17
+ echo $hostname > /etc/hostname
18
+ if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
19
+ sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" \
20
+ /etc/hosts
21
+ else
22
+ sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" \
23
+ /etc/hosts
24
+ fi
25
+ service hostname start
26
+ }
27
+
28
+ set_hostname_for_debian() {
29
+ if hostname --fqdn | grep -q "^${hostname}$" || hostname --short | grep -q "^${hostname}$" ; then
30
+ info "Hostname is correct, so skipping..."
31
+ return
32
+ fi
33
+
34
+ local host_first="$(echo $hostname | cut -d . -f 1)"
35
+
36
+ sed -r -i "s/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1${hostname} ${host_first}/" \
37
+ /etc/hosts
38
+ echo $host_first > /etc/hostname
39
+ hostname -F /etc/hostname
40
+ }
41
+
42
+ set_hostname_for_el() {
43
+ if hostname | grep -q "$hostname" > /dev/null ; then
44
+ info "-----> Hostname is correct, so skipping..."
45
+ return
46
+ fi
47
+
48
+ local host_first="$(echo $hostname | cut -d . -f 1)"
49
+ local hostnames="${hostname} ${host_first}"
50
+
51
+ sed -i "s/HOSTNAME=.*/HOSTNAME=${hostname}/" /etc/sysconfig/network
52
+
53
+ if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
54
+ sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" /etc/hosts
55
+ else
56
+ sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" \
57
+ /etc/hosts
58
+ fi
59
+ /bin/hostname ${hostname}
60
+ }
@@ -0,0 +1,116 @@
1
+ # taken from http://opscode.com/chef/install.sh
2
+ #
3
+ # only the platform detection is extracted. the script adds a `set -e` at the
4
+ # beginning and two lines at the end that output the platform and
5
+ # platform_version. Everything else is mostly unmodified.
6
+ #
7
+
8
+ set -e
9
+
10
+ machine=$(echo -e `uname -m`)
11
+
12
+ # Retrieve Platform and Platform Version
13
+ if [ -f "/etc/lsb-release" ];
14
+ then
15
+ platform=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]')
16
+ platform_version=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2)
17
+ elif [ -f "/etc/debian_version" ];
18
+ then
19
+ platform="debian"
20
+ platform_version=$(echo -e `cat /etc/debian_version`)
21
+ elif [ -f "/etc/redhat-release" ];
22
+ then
23
+ platform=$(sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]')
24
+ platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release)
25
+
26
+ # If /etc/redhat-release exists, we act like RHEL by default
27
+ if [ "$platform" = "fedora" ];
28
+ then
29
+ # Change platform version for use below.
30
+ platform_version="6.0"
31
+ fi
32
+ platform="el"
33
+ elif [ -f "/etc/system-release" ];
34
+ then
35
+ platform=$(sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
36
+ platform_version=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]')
37
+ # amazon is built off of fedora, so act like RHEL
38
+ if [ "$platform" = "amazon linux ami" ];
39
+ then
40
+ platform="el"
41
+ platform_version="6.0"
42
+ fi
43
+ # Apple OS X
44
+ elif [ -f "/usr/bin/sw_vers" ];
45
+ then
46
+ platform="mac_os_x"
47
+ # Matching the tab-space with sed is error-prone
48
+ platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }')
49
+
50
+ major_version=$(echo $platform_version | cut -d. -f1,2)
51
+ case $major_version in
52
+ "10.6") platform_version="10.6" ;;
53
+ "10.7") platform_version="10.7" ;;
54
+ "10.8") platform_version="10.7" ;;
55
+ *) echo "No builds for platform: $major_version"
56
+ report_bug
57
+ exit 1
58
+ ;;
59
+ esac
60
+
61
+ # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
62
+ x86_64=$(sysctl -n hw.optional.x86_64)
63
+ if [ $x86_64 -eq 1 ]; then
64
+ machine="x86_64"
65
+ fi
66
+ elif [ -f "/etc/release" ];
67
+ then
68
+ platform="solaris2"
69
+ machine=$(/usr/bin/uname -p)
70
+ platform_version=$(/usr/bin/uname -r)
71
+ elif [ -f "/etc/SuSE-release" ];
72
+ then
73
+ if grep -q 'Enterprise' /etc/SuSE-release;
74
+ then
75
+ platform="sles"
76
+ platform_version=$(awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release)
77
+ else
78
+ platform="suse"
79
+ platform_version=$(awk '/^VERSION =/ { print $3 }' /etc/SuSE-release)
80
+ fi
81
+ fi
82
+
83
+ if [ "x$platform" = "x" ];
84
+ then
85
+ echo "Unable to determine platform version!"
86
+ report_bug
87
+ exit 1
88
+ fi
89
+
90
+ # Mangle $platform_version to pull the correct build
91
+ # for various platforms
92
+ major_version=$(echo $platform_version | cut -d. -f1)
93
+ case $platform in
94
+ "el")
95
+ case $major_version in
96
+ "5") platform_version="5" ;;
97
+ "6") platform_version="6" ;;
98
+ esac
99
+ ;;
100
+ "debian")
101
+ case $major_version in
102
+ "5") platform_version="6";;
103
+ "6") platform_version="6";;
104
+ esac
105
+ ;;
106
+ esac
107
+
108
+ if [ "x$platform_version" = "x" ];
109
+ then
110
+ echo "Unable to determine platform version!"
111
+ report_bug
112
+ exit 1
113
+ fi
114
+
115
+ echo $platform
116
+ echo $platform_version
@@ -1,57 +1,39 @@
1
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 @config[:knife] && @config[:knife][:log_level] == :debug -%>
16
+
2
17
  <%=
3
18
  if knife_config[:bootstrap_proxy]
4
19
  %{export http_proxy="#{knife_config[:bootstrap_proxy]}"}
5
20
  end
6
21
  -%>
7
-
8
22
  export hostname="<%= @config[:chef_node_name] %>"
9
23
  export webui_password="<%= ENV['WEBUI_PASSWORD'] %>"
10
24
  export amqp_password="<%= ENV['AMQP_PASSWORD'] %>"
25
+
11
26
  export DEBIAN_FRONTEND=noninteractive
12
27
 
13
- set -x
28
+ <%= render "common.sh" %>
29
+
30
+ <%= render "platform_and_version.sh" %>
31
+
32
+ <%= render "set_hostname.sh" %>
14
33
 
15
34
  setup() {
16
35
  apt-get update
17
36
  apt-get install -y lsb-release
18
-
19
- platform="$(lsb_release -is | tr [[:upper:]] [[:lower:]])"
20
- platform_version="$(lsb_release -rs)"
21
- }
22
-
23
- set_hostname_for_ubuntu() {
24
- if hostname | grep -q "$hostname" >/dev/null ; then
25
- printf "Hostname is correct, so skipping...\n"
26
- return
27
- fi
28
-
29
- local host_first="$(echo $hostname | cut -d . -f 1)"
30
- local hostnames="${hostname} ${host_first}"
31
-
32
- echo $hostname > /etc/hostname
33
- if egrep -q "^127.0.1.1[[:space:]]" /etc/hosts >/dev/null ; then
34
- sed -i "s/^\(127[.]0[.]1[.]1[[:space:]]\+\)/\1${hostnames} /" \
35
- /etc/hosts
36
- else
37
- sed -i "s/^\(127[.]0[.]0[.]1[[:space:]]\+.*\)$/\1\n127.0.1.1 ${hostnames} /" \
38
- /etc/hosts
39
- fi
40
- service hostname start
41
- }
42
-
43
- set_hostname_for_debian() {
44
- if hostname --fqdn | grep -q "^${hostname}$" || hostname --short | grep -q "^${hostname}$" ; then
45
- printf "Hostname is correct, so skipping...\n"
46
- return
47
- fi
48
-
49
- local host_first="$(echo $hostname | cut -d . -f 1)"
50
-
51
- sed -r -i "s/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1${hostname} ${host_first}/" \
52
- /etc/hosts
53
- echo $host_first > /etc/hostname
54
- hostname -F /etc/hostname
55
37
  }
56
38
 
57
39
  add_opscode_apt_repo() {
@@ -123,5 +105,5 @@ add_opscode_apt_repo
123
105
  install_chef_server
124
106
  enable_ssl_proxy
125
107
 
126
- printf -- "-----> Bootstraping Chef Server on ${hostname} is complete.\n"
108
+ banner "Bootstraping Chef Server on ${hostname} is complete."
127
109
  '