-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathprovision-rackspace-controller.sh
More file actions
executable file
·96 lines (84 loc) · 2.59 KB
/
provision-rackspace-controller.sh
File metadata and controls
executable file
·96 lines (84 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
#
# Usage: ./provision-rackspace-controller.sh <region>
#
if [ -z $1 ]; then
echo usage: $0 [region]
exit 1
fi
function echo_color {
echo -e "\033[1m$1\033[0m"
}
THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
CONTRIB_DIR=$(dirname $THIS_DIR)
# check for Deis' general dependencies
if ! $CONTRIB_DIR/check-deis-deps.sh; then
echo 'Deis is missing some dependencies.'
exit 1
fi
# check for knife-rackspace
if ! knife rackspace server list > /dev/null; then
echo 'Please install the knife-rackspace Ruby gem and configure knife.rb.'
exit 1
fi
#################
# chef settings #
#################
node_name=deis-controller
run_list="recipe[deis::controller]"
chef_version=11.6.2
######################
# Rackspace settings #
######################
region=$1
# see contrib/prepare-rackspace-image.sh for instructions
# on creating your own deis-optmized images
if ! [[ "ord dfw iad lon syd" =~ $region ]]; then
echo "Unrecognized region: $region"
exit 1
fi
flavor=$(knife rackspace flavor list | grep '2GB Standard Instance' | awk '{print $1}')
image=$(knife rackspace image list --rackspace-region $region | grep 'deis-base-image' | awk '{print $1}')
if [[ -z $image ]]; then
echo "Can't find saved image \"deis-base-image\" in region $region. Please follow the"
echo "instructions in prepare-rackspace-image.sh before provisioning a Deis controller."
echo
exit 1
fi
################
# SSH settings #
################
key_name=deis-controller
ssh_key_path=~/.ssh/$key_name
ssh_user="ubuntu" # doesn't work?
# create ssh keypair and store it
if ! test -e $ssh_key_path; then
echo_color "Creating new SSH key: $key_name"
set -x
ssh-keygen -f $ssh_key_path -t rsa -N '' -C "deis-controller" >/dev/null
set +x
echo_color "Saved to $ssh_key_path"
else
echo_color "WARNING: SSH key $ssh_key_path exists"
fi
# create data bags
knife data bag create deis-users 2>/dev/null
knife data bag create deis-formations 2>/dev/null
knife data bag create deis-apps 2>/dev/null
# trigger Rackspace instance bootstrap
echo_color "Provisioning $node_name with knife rackspace..."
set -x
knife rackspace server create \
--bootstrap-version $chef_version \
--rackspace-region $region \
--image $image \
--flavor $flavor \
--rackspace-metadata "{\"Name\": \"$node_name\"}" \
--rackspace-disk-config MANUAL \
--identity-file $ssh_key_path \
--server-name $node_name \
--node-name $node_name \
--run-list $run_list
set +x
# Need Chef admin permission in order to add and remove nodes and clients
echo -e "\033[35mPlease ensure that \"deis-controller\" is added to the Chef \"admins\" group.\033[0m"