From 87ff517a2f237a6576fc1ae90002263ecb945da7 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 21 Mar 2012 11:22:38 +0100 Subject: [PATCH] Add SUSE as a supported distro - includes default AutoYaST Profile - initial crowbar_join script for SUSE based on the Red Hat variant (called by AutoYaST after installation) - Adjusts setup_base_images recipe to generate pxe config for SUSE --- .../provisioner/recipes/setup_base_images.rb | 27 ++- .../templates/default/autoyast.xml.erb | 165 +++++++++++++++++ .../default/crowbar_join.suse.sh.erb | 170 ++++++++++++++++++ .../crowbar/bc-template-provisioner.json | 8 +- 4 files changed, 368 insertions(+), 2 deletions(-) create mode 100644 chef/cookbooks/provisioner/templates/default/autoyast.xml.erb create mode 100644 chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb diff --git a/chef/cookbooks/provisioner/recipes/setup_base_images.rb b/chef/cookbooks/provisioner/recipes/setup_base_images.rb index 0d802442..8918e41d 100755 --- a/chef/cookbooks/provisioner/recipes/setup_base_images.rb +++ b/chef/cookbooks/provisioner/recipes/setup_base_images.rb @@ -1,4 +1,5 @@ # Copyright 2011, Dell +# Copyright 2012, SUSE Linux Products GmbH # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License @@ -197,7 +198,7 @@ node[:provisioner][:repositories][os_token][f] = case when os_token =~ /ubuntu/ "deb http://#{admin_ip}:#{web_port}/#{os_token}/crowbar-extra/#{f} /" - when os_token =~ /(redhat|centos)/ + when os_token =~ /(redhat|centos|suse)/ "baseurl=http://#{admin_ip}:#{web_port}/#{os_token}/crowbar-extra/#{f}" else raise ::RangeError.new("Cannot handle repos for #{os_token}") @@ -217,6 +218,30 @@ # These should really be made libraries or something. case + when /^(suse)/ =~ os + # Add base OS install repo for suse + node[:provisioner][:repositories][os_token]["base"] = "baseurl=http://#{admin_ip}:#{web_port}/#{os_token}/install" + template "#{os_dir}/autoyast.xml" do + mode 0644 + source "autoyast.xml.erb" + owner "root" + group "root" + variables( + :admin_node_ip => admin_ip, + :web_port => web_port, + :repos => node[:provisioner][:repositories][os_token], + :admin_web => admin_web, + :crowbar_join => "#{web_path}/crowbar_join.sh") + end + + template "#{os_dir}/crowbar_join.sh" do + mode 0644 + owner "root" + group "root" + source "crowbar_join.suse.sh.erb" + variables(:admin_ip => admin_ip) + end + when /^(redhat|centos)/ =~ os # Add base OS install repo for redhat/centos node[:provisioner][:repositories][os_token]["base"] = "baseurl=http://#{admin_ip}:#{web_port}/#{os_token}/install/Server" diff --git a/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb b/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb new file mode 100644 index 00000000..35c1836a --- /dev/null +++ b/chef/cookbooks/provisioner/templates/default/autoyast.xml.erb @@ -0,0 +1,165 @@ + + + + + false + + + + + false + false + true + false + true + + + none + + + + true + true + true + true + true + true + + + + + + root + root + false + + + + + + true + + true + crowbar.site + auto + false + + false + + false + + + + + true + + CT_DISK + all + + + + + + + + + + + + + + + + autoyast2-installation + + + Minimal + base + + + diff --git a/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb new file mode 100644 index 00000000..4c503e1b --- /dev/null +++ b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb @@ -0,0 +1,170 @@ +#!/bin/bash +# Copyright 2011, Dell +# Copyright 2012, SUSE Linux Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +HTTP_SERVER="<%= @admin_ip %>:8091" +IP=${HTTP_SERVER%:*} + +exec 2>>/var/log/crowbar-join.errlog + +export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ' +set -x + +if [[ ! -d /var/log/chef/ ]]; then + mkdir -p /var/log/chef/ +fi + +if [[ -f /etc/crowbar.install.key ]]; then + export CROWBAR_KEY="$(cat /etc/crowbar.install.key)" +fi + +# Run a command and log its output. +log_to() { + # $1 = install log to log to + # $@ = rest of args + local __log="/var/log/crowbar-join-$1" + local __timestamp="$(date '+%F %T %z')" + shift + printf "\n%s\n" "$__timestamp: Running $*" | \ + tee -a "$__log.err" >> "$__log.log" + local _ret=0 + if "$@" 2>> "$__log.err" >>"$__log.log"; then + _ret=0 + else + _ret="$?" + echo "$__timestamp: $* failed." + echo "See $__log.log and $__log.err for more information." + fi + printf "\n$s\n--------\n" "$(date '+%F %T %z'): Done $*" | \ + tee -a "$__log.err" >> "$__log.log" + return $_ret +} + +post_state() { + local curlargs=(-o "/var/log/$1-$2.json" --connect-timeout 60 -s \ + -L -X POST --data-binary "{ \"name\": \"$1\", \"state\": \"$2\" }" \ + -H "Accept: application/json" -H "Content-Type: application/json" \ + --max-time 240) + [[ $CROWBAR_KEY ]] && curlargs+=(-u "$CROWBAR_KEY" --digest --anyauth) + curl "${curlargs[@]}" "http://$IP:3000/crowbar/crowbar/1.0/transition/default" +} + +# Spin while we wait for the interface to come up. +echo "Waiting on our network interface to come up..." +while ! ip addr | grep -v " lo" | grep -q "inet " +do + sleep 1 +done + +# Get our hostname +HOSTNAME=$(hostname -f) + +sync_time() { + # stop ntpd before we run ntpdate, and start it again afterwards. + service ntp stop + # Warning! Newer sntp releases use different options (e.g. the one + # on openSUSE 12.1 + while ! sntp -P no -r $IP; do + echo "Waiting for NTP server" + sleep 1 + done +} + +echo "Synchronizing time (pass 1)" +sync_time + +# Mark us as readying, and get our cert. +post_state $HOSTNAME "readying" +final_state="ready" +mkdir -p /etc/chef +curl -o /etc/chef/validation.pem \ + "http://$HTTP_SERVER/validation.pem" + +if [[ ! -x /etc/init.d/bluepill ]]; then + # Make sure that the client knows how to talk to the server + echo "chef_server_url \"http://$IP:4000\"" >/etc/chef/client.rb + + # Install Chef + echo "Installing Chef..." + + while ! log_to zypper zypper -n refresh ; do + echo "Failed to do zypper refresh, wait and try again" + sleep 1 + done + while ! log_to zypper zypper -n install rubygem-chef ; do + echo "Failed to do zypper install, wait and try again" + sleep 1 + done + + log_to chef chkconfig -a chef-client +fi + + +# Run Chef +echo "Syncing time (pass 2)" +sync_time + +# Until we arrange for the network to transisiton from using +# DHCP somewhere else, the first run of chef-client will always die due to +# the networking barclamp changing the IP address from dhcp to static. +# We will try to pick up and run with it. +echo "Running Chef Client (pass 1)" +log_to chef chef-client -l debug + +# Make sure our interfaces are as up as we can get them +echo "Ensuring that our network interfaces are up." +log_to ifup /sbin/service network restart + +# Only transition to problem state if the second run fails. +echo "Running Chef Client (pass 2)" +if ! log_to chef chef-client -l debug; then + log_to ifup /sbin/service network restart + post_state $HOSTNAME "recovering" + echo "Error Path" + echo "Syncing Time (pass 3)" + sync_time + echo "Removing Chef Cache" + rm -rf /var/cache/chef/* + echo "Running Chef Client (pass 3) - cache cleanup" + if ! log_to chef chef-client -l debug; then + log_to ifup /sbin/service network restart + echo "Error Path" + echo "Syncing Time (pass 4)" + sync_time + echo "Removing Chef Cache" + rm -rf /var/cache/chef/* + echo "Checking Keys" + rm -f /etc/chef/client.pem + post_state $HOSTNAME "hardware-updated" + echo "Running Chef Client (pass 4) - password cleanup" + if ! log_to chef chef-client -l debug; then + log_to ifup /sbin/service network restart + echo "chef-client run failed four times, giving up." + echo "Failed" + printf "Our IP address is: %s\n" "$(ip addr show)" + final_state="problem" + fi + fi +fi + +# Transition to our final state +post_state $HOSTNAME "$final_state" + +log_to time service ntp start +# Fire up bluepill, and let it keep chef-client up. +service chef-client start + +echo "Done" diff --git a/chef/data_bags/crowbar/bc-template-provisioner.json b/chef/data_bags/crowbar/bc-template-provisioner.json index 7cee981a..98535a81 100644 --- a/chef/data_bags/crowbar/bc-template-provisioner.json +++ b/chef/data_bags/crowbar/bc-template-provisioner.json @@ -45,7 +45,13 @@ "initrd": "images/pxeboot/initrd.img", "kernel": "images/pxeboot/vmlinuz", "append": "method=%os_install_site% ks=%os_site%/compute.ks ksdevice=bootif" - } + }, + "suse-11.2": { + "initrd": "boot/x86_64/loader/initrd", + "kernel": "boot/x86_64/loader/linux", + "append": "install=%os_install_site% autoyast=%os_site%/autoyast.xml" + } + }, "root": "/tftpboot", "web_port": 8091,