forked from crowbar/barclamp-provisioner
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request crowbar#19 from rha-cb/pull-req-feature-suse-integ…
…ration-cleanup-master-87ff517a2f Initial changes for SUSE support in provisioner, logging and network [2/7]
- Loading branch information
Showing
4 changed files
with
368 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
chef/cookbooks/provisioner/templates/default/autoyast.xml.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE profile> | ||
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> | ||
<deploy_image> | ||
<image_installation config:type="boolean">false</image_installation> | ||
</deploy_image> | ||
<general> | ||
<ask-list config:type="list"/> | ||
<mode> | ||
<confirm config:type="boolean">false</confirm> | ||
<final_halt config:type="boolean">false</final_halt> | ||
<final_reboot config:type="boolean">true</final_reboot> | ||
<halt config:type="boolean">false</halt> | ||
<second_stage config:type="boolean">true</second_stage> | ||
</mode> | ||
<mouse> | ||
<id>none</id> | ||
</mouse> | ||
<proposals config:type="list"/> | ||
<signature-handling> | ||
<accept_file_without_checksum config:type="boolean">true</accept_file_without_checksum> | ||
<accept_non_trusted_gpg_key config:type="boolean">true</accept_non_trusted_gpg_key> | ||
<accept_unknown_gpg_key config:type="boolean">true</accept_unknown_gpg_key> | ||
<accept_unsigned_file config:type="boolean">true</accept_unsigned_file> | ||
<accept_verification_failed config:type="boolean">true</accept_verification_failed> | ||
<import_gpg_key config:type="boolean">true</import_gpg_key> | ||
</signature-handling> | ||
<storage/> | ||
</general> | ||
<users config:type="list"> | ||
<user> | ||
<username>root</username> | ||
<user_password>root</user_password> | ||
<encrypted config:type="boolean">false</encrypted> | ||
<forename/> | ||
<surname/> | ||
</user> | ||
</users> | ||
<networking> | ||
<keep_install_network config:type="boolean">true</keep_install_network> | ||
<dns> | ||
<dhcp_hostname config:type="boolean">true</dhcp_hostname> | ||
<domain>crowbar.site</domain> | ||
<resolv_conf_policy>auto</resolv_conf_policy> | ||
<write_hostname config:type="boolean">false</write_hostname> | ||
</dns> | ||
<managed config:type="boolean">false</managed> | ||
<routing> | ||
<ip_forward config:type="boolean">false</ip_forward> | ||
</routing> | ||
</networking> | ||
<partitioning config:type="list"> | ||
<drive> | ||
<initialize config:type="boolean">true</initialize> | ||
<partitions config:type="list"/> | ||
<type config:type="symbol">CT_DISK</type> | ||
<use>all</use> | ||
</drive> | ||
</partitioning> | ||
<scripts> | ||
<pre-scripts config:type="list"> | ||
<script> | ||
<debug config:type="boolean">true</debug> | ||
<feedback config:type="boolean">false</feedback> | ||
<notification>Please wait while script is running...</notification> | ||
<source> | ||
<![CDATA[ | ||
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ' | ||
HTTP_SERVER="<%= @admin_node_ip %>:<%= @web_port %>" | ||
IP="<%= @admin_node_ip %>" | ||
HOSTNAME=$(hostname) | ||
|
||
key_re='crowbar\.install\.key=([^ ]+)' | ||
if [[ $(cat /proc/cmdline) =~ $key_re ]]; then | ||
export CROWBAR_KEY="${BASH_REMATCH[1]}" | ||
echo "$CROWBAR_KEY" >/mnt/etc/crowbar.install.key | ||
elif [[ -f /mnt/etc/crowbar.install.key ]]; then | ||
export CROWBAR_KEY="$(cat /mnt/etc/crowbar.install.key)" | ||
fi | ||
|
||
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" | ||
} | ||
|
||
post_state $HOSTNAME "installing" | ||
]]> | ||
</source> | ||
</script> | ||
</pre-scripts> | ||
<chroot-scripts config:type="list"> | ||
<script> | ||
<chrooted config:type="boolean">false</chrooted> | ||
<debug config:type="boolean">true</debug> | ||
<filename>crowbar_post</filename> | ||
<source> | ||
<![CDATA[ | ||
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ' | ||
HTTP_SERVER="<%= @admin_node_ip %>:<%= @web_port %>" | ||
IP="<%= @admin_node_ip %>" | ||
HOSTNAME=$(hostname) | ||
|
||
key_re='crowbar\.install\.key=([^ ]+)' | ||
if [[ $(cat /proc/cmdline) =~ $key_re ]]; then | ||
export CROWBAR_KEY="${BASH_REMATCH[1]}" | ||
echo "$CROWBAR_KEY" >/mnt/etc/crowbar.install.key | ||
elif [[ -f /mnt/etc/crowbar.install.key ]]; then | ||
export CROWBAR_KEY="$(cat /mnt/etc/crowbar.install.key)" | ||
fi | ||
|
||
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" | ||
} | ||
|
||
mkdir -p /mnt/root/.ssh | ||
chmod 700 /mnt/root/.ssh | ||
if ! curl -s -o /mnt/root/.ssh/authorized_keys.wget \ | ||
http://$HTTP_SERVER/authorized_keys; then | ||
rm -f /mnt/root/.ssh/authorized_keys.wget | ||
else | ||
chmod 644 /mnt/root/.ssh/authorized_keys | ||
cat /mnt/root/.ssh/authorized_keys.wget >> /mnt/root/.ssh/authorized_keys | ||
rm -f /mnt/root/.ssh/authorized_keys.wget | ||
fi | ||
|
||
curl -s -o /mnt/etc/init.d/crowbar_join.sh <%= @crowbar_join %> | ||
chmod +x /mnt/etc/init.d/crowbar_join.sh | ||
|
||
sleep 30 | ||
|
||
post_state $HOSTNAME "installed" | ||
|
||
# Wait for DHCP to update - this is mainly for virtual environments or really large deploys | ||
sleep 30 | ||
sync | ||
]]> | ||
</source> | ||
</script> | ||
</chroot-scripts> | ||
<init-scripts config:type="list"> | ||
<script> | ||
<filename>crowbar_join</filename> | ||
<location>http://<%= @admin_node_ip %>:8091/suse-11.2/crowbar_join.sh</location> | ||
</script> | ||
</init-scripts> | ||
</scripts> | ||
<software> | ||
<packages config:type="list"> | ||
<package>autoyast2-installation</package> | ||
</packages> | ||
<patterns config:type="list"> | ||
<pattern>Minimal</pattern> | ||
<pattern>base</pattern> | ||
</patterns> | ||
</software> | ||
</profile> |
170 changes: 170 additions & 0 deletions
170
chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters