-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud-init-userdata
More file actions
84 lines (75 loc) · 3.1 KB
/
cloud-init-userdata
File metadata and controls
84 lines (75 loc) · 3.1 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
#!/bin/bash
#
# Build devstack
# This script will install devstack with the same configuration and modules as in https://github.com/patux/mydevstack
# on the host it is called perfect to run on top of openstack vms, looking fwd to do CI/CD
#
# Requires/Installs puppet
# Geronimo Orozco gorozco@gmail.com
#
# parse_yaml taken from:
# From: http://stackoverflow.com/questions/5014632/how-can-i-parse-a-yaml-file-from-a-linux-shell-script
#
if [ "$EUID" -ne "0" ]; then
echo "$(date +"%F %T.%N") ERROR : This script must be run as root." >&2
exit 1
fi
# Sanitize the environment
apt-get update
apt-get -y --force-yes -o Dpkg::Options::="--force-confnew" install puppet
[ -d /tmp/mydevstack ] && rm -rf /tmp/mydevstack : #donothing
apt-get install git -y
# if you are behind a proxy uncomment and edit next line
# export https_proxy=http://myproxy.url.com:port
git clone https://github.com/patux/mydevstack.git /tmp/mydevstack --recursive
cd /tmp/mydevstack
# Remove run devstack in the the backgroud
# sed -i s/'\&'//g puppet/modules/devstack/manifests/init.pp
# Create your common.yaml with your proxy variables if needed
# Replace the values as you need
# If you are not behind a proxy use nil as a value for proxy and no_proxy values variables
cat << EOF > etc/common.yaml
http_proxy_host: http://myproxy.url.com
http_proxy_port: 3128
https_proxy_host: http://myproxy.url.com
https_proxy_port: 3128
socks_proxy_host: socks://myproxy.url.com
socks_proxy_port: 8080
no_proxy_domains: .yourcompany.com,.mylocalnet.com,169.254.169.254
ssh_dir: '~/.ssh/'
memory: 6144
install_devstack: true
devstack_branch: master
devstack_setup: simple
devstack_user: stack
EOF
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
# if puppet is not installed install it
if [ -z `dpkg -la | grep "puppet " | awk '{print $2}'` ] ; then
apt-get -y --force-yes -o Dpkg::Options::="--force-confnew" install puppet
fi
for i in `parse_yaml etc/common.yaml | tr -d '"'` ;
do
export FACTER_$i
done
# if proxy variables are set then we need to call puppet with these variables
if [ $FACTER_http_proxy_host != "nil" ]; then
no_proxy=$FACTER_no_proxy_domains puppet apply --verbose --node_name_value `hostname -f` --http_proxy_host $FACTER_http_proxy_host --http_proxy_port $FACTER_http_proxy_port --modulepath puppet/modules --manifestdir puppet/manifests --detailed-exitcodes puppet/manifests/vagrant.pp &>/var/log/devstack_install.log
else
puppet apply --verbose --node_name_value `hostname -f` --modulepath puppet/modules --manifestdir puppet/manifests --detailed-exitcodes puppet/manifests/vagrant.pp &>/var/log/devstack_install.log
fi