Skip to content

Commit a3090b9

Browse files
author
Gabriel Monroy
committed
Merge pull request #348 from tombh/digital-ocean-provision-error-tolerance
Use DO creds from knife.rb. Also, respond to failed knife bootstrap by deleting things.
2 parents c807cc2 + 910146f commit a3090b9

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

contrib/digitalocean/provision-digitalocean-controller.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ if ! $CONTRIB_DIR/check-deis-deps.sh; then
2424
fi
2525

2626
# connection details for using digital ocean's API
27-
client_id=$DIGITALOCEAN_CLIENT_ID
28-
api_key=$DIGITALOCEAN_API_KEY
27+
client_id=${DIGITALOCEAN_CLIENT_ID:-$(knife exec -E"puts Chef::Config[:knife][:digital_ocean_client_id]")}
28+
api_key=${DIGITALOCEAN_API_KEY:-$(knife exec -E"puts Chef::Config[:knife][:digital_ocean_api_key]")}
2929

3030
# Check that client ID and API key was set
3131
if test -z $client_id; then
32-
echo "Please add your client id to ${knife_file}."
32+
echo "Please add your Digital Ocean Client ID to the shell's environment or knife.rb."
3333
fi
3434

3535
if test -z $api_key; then
36-
echo "Please add your api key to ${knife_file}."
36+
echo "Please add your Digital Ocean API Key to the shell's environment or knife.rb."
3737
fi
3838

3939
#################
@@ -111,7 +111,23 @@ knife digital_ocean droplet create \
111111
--identity-file $ssh_key_path \
112112
--bootstrap \
113113
--run-list $run_list
114+
result=$?
114115
set +x
115116

116-
# Need Chef admin permission in order to add and remove nodes and clients
117-
echo -e "\033[35mPlease ensure that \"deis-controller\" is added to the Chef \"admins\" group.\033[0m"
117+
if [ $result -ne 0 ]; then
118+
echo_color "Knife botstrap failed."
119+
# Destroy droplet
120+
droplet_id=$(knife digital_ocean droplet list | grep deis-controller | awk '{print $1}')
121+
echo_color "Destroying Droplet $droplet_id..."
122+
knife digital_ocean droplet destroy -S $droplet_id
123+
# Remove node and client from Chef Server
124+
echo_color "Deleting Chef client..."
125+
knife client delete deis-controller -y
126+
echo_color "Deleting Chef node..."
127+
knife node delete deis-controller -y
128+
else
129+
echo_color "Knife bootstrap successful."
130+
# Need Chef admin permission in order to add and remove nodes and clients
131+
echo -e "\033[35mPlease ensure that \"deis-controller\" is added to the Chef \"admins\" group.\033[0m"
132+
fi
133+

0 commit comments

Comments
 (0)