forked from bodepd/folsom-manifests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_os_puppet
executable file
·172 lines (148 loc) · 5.41 KB
/
install_os_puppet
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# install_os_puppet by Cisco Systems, Inc. is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
#
# This script runs the basic steps for preparing to auto-deploy OpenStack as per the Cisco Edition process
# The manual steps are documented at http://docwiki.cisco.com/wiki/OpenStack:Folsom
#
# This script: updates apt, and makes sure that the system is up to date with the current Ubuntu baseline
# It then downloads the current set of Cisco validated puppet modules and a set of baseline manifests from the
# Cisco github repository
# If a proxy is necessary in order to download files from the internet, then either a proxy target can be passed
# to the script, or the environmet variables can be pre-set before running the script locally.
#
#
# set default tag to be retrieved
CURRENT_TAG=2012.2.3
set -o errexit
usage() {
cat <<EOF
usage: $0 options
OPTIONS:
-h Show this message
-p http proxy i.e. -p http://username:password@host:port/
-t release tag i.e. -t 2012.2.3
EOF
}
export -f usage
# wrapper all commands with sudo in case this is not run as root
# also map in a proxy in case it was passed as a command line argument
function run_cmd () {
if [ -z "$PROXY" ]; then
sudo $*
else
sudo env http_proxy=$PROXY https_proxy=$PROXY $*
fi
}
export -f run_cmd
# similar functions with sudo, optional proxy, and git commands
# to emulate a git clone by tag command that doesn't exist
function git_clone_tag () {
if [ -z "$PROXY" ]; then
sudo git clone https://github.com/CiscoSystems/folsom-manifests /root/cisco-folsom-manifests
sudo bash -c "cd /root/cisco-folsom-manifests && git checkout -q $CURRENT_TAG"
else
sudo env https_proxy=$PROXY git clone https://github.com/CiscoSystems/folsom-manifests /root/cisco-folsom-manifests
sudo env https_proxy=$PROXY bash -c "cd /root/cisco-folsom-manifests && git checkout -q $CURRENT_TAG"
fi
}
export -f git_clone_tag
function git_fetch_tag () {
if [ -z "$PROXY" ]; then
sudo bash -c "cd /root/cisco-folsom-manifests && git fetch --all && git checkout -q $CURRENT_TAG"
else
sudo env https_proxy=$PROXY bash -c "cd /root/cisco-folsom-manifests && git fetch --all && git checkout -q $CURRENT_TAG"
fi
}
export -f git_fetch_tag
# Define some useful APT parameters to make sure you get the latest versions of code
APT_CONFIG="-o Acquire::http::No-Cache=True -o Acquire::BrokenProxy=true -o Acquire::Retries=3"
# check if the environment is set up for http and https proxies
if [ -n "$http_proxy" ]; then
if [ -z "$https_proxy" ]; then
echo "Please set https_proxy env variable."
exit 1
fi
PROXY=$http_proxy
fi
# parse CLI options
while getopts "h:p:t:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
p)
PROXY=$OPTARG
export http_proxy=$PROXY
export https_proxy=$PROXY
;;
t)
CURRENT_TAG=$OPTARG export CURRENT_TAG
;;
esac
done
# Make sure the apt repository list is up to date
echo -e "\n\nUpdate apt repository...\n\n"
if ! run_cmd apt-get $APT_CONFIG update; then
echo "Can't update apt repository"
exit 1
fi
# Install prerequisite packages
echo "Installing prerequisite apps: git, puppet, ipmitool, python-software-properties.."
if ! run_cmd apt-get $APT_CONFIG install -qym git puppet ipmitool python-software-properties; then
echo "Can't install prerequisites!..."
exit 1
fi
# Grab the Cisco puppet global manifests (site.pp, etc.), try to update a previously downloaded set first
echo "Cloning folsom-manifests multi-node repository branch from github.com..."
if [ -d /root/cisco-folsom-manifests ] ; then
echo -e "Looks like perhaps you ran this script before? We'll try to update your cisco-folsom-manifests directory, just in case..."
if ! git_fetch_tag ; then
echo "That did not work. Perhaps rename your cisco-folsom-manifests directory, and try again?"
exit 1
fi
fi
# Get a new set, as there was no previous download
if [ ! -d /root/cisco-folsom-manifests ] ; then
if ! git_clone_tag ; then
echo "Can't run git clone!"
exit 1
fi
fi
echo "Copying manifests examples to manifest dir..."
if ! run_cmd cp /root/cisco-folsom-manifests/manifests/* /etc/puppet/manifests/ ;then
echo "Can't copy sample manifests!!!"
exit 1
fi
if [ -d /root/cisco-folsom-manifests/templates ]
then
echo "Copying templates to templates dir..."
if ! run_cmd cp -R /root/cisco-folsom-manifests/templates /etc/puppet/ ;then
echo "Can't copy sample manifests!!!"
exit 1
fi
fi
# Update APT again, to capture any changes and updates driven by the newly loaded code
echo -e "\n\nUpdated apt repository...\n\n"
if ! run_cmd apt-get $APT_CONFIG update; then
echo "Can't update apt repository"
exit 1
fi
# Make sure the distro is up to date
echo -e "\n\nUpdate packages...\n\n"
if ! run_cmd apt-get $APT_CONFIG dist-upgrade -y; then
echo "Can't update packages"
exit 1
fi
# Change to the manifests directory, as the puppet-modules.sh script expects to find a file in the local
# directory that lists the modules to download
cd /etc/puppet/manifests
# Load the lateast modules.
echo -e "\n\nInstalling Cisco Validated puppet openstack modules...\n\n"
if ! run_cmd sh puppet-modules.sh ; then
echo "Can't install puppet modules..."
exit 1
fi
echo -e "\n\nSUCCESS!!!!\n\n Now, go edit your site.pp file in /etc/puppet/manifests, and then run 'puppet apply -v /etc/puppet/manifests/site.pp"
exit 0