3 #Deploy script to install provisioning server for Foreman/QuickStack
4 #author: Tim Rozet (trozet@redhat.com)
6 #Uses Vagrant and VirtualBox
7 #VagrantFile uses bootsrap.sh which Installs Khaleesi
8 #Khaleesi will install and configure Foreman/QuickStack
11 #Supports 3 or 4 network interface configuration
12 #Target system must be RPM based
13 #Ensure the host's kernel is up to date (yum update)
14 #Provisioned nodes expected to have following order of network connections (note: not all have to exist, but order is maintained):
16 #eth1- private network (+storage network in 3 NIC config)
18 #eth3- storage network
19 #script assumes /24 subnet mask
31 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
32 echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
33 echo -e "\nUsage:\n$0 [arguments] \n"
34 echo -e "\n -no_parse : No variable parsing into config. Flag. \n"
35 echo -e "\n -base_config : Full path of settings file to parse. Optional. Will provide a new base settings file rather than the default. Example: -base_config /opt/myinventory.yml \n"
38 ##find ip of interface
39 ##params: interface name
41 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
46 ##assumes a /24 subnet
48 baseaddr="$(echo $1 | cut -d. -f1-3)"
49 lsv="$(echo $1 | cut -d. -f4)"
50 if [ "$lsv" -ge 254 ]; then
57 ##removes the network interface config from Vagrantfile
59 ##assumes you are in the directory of Vagrantfile
60 function remove_vagrant_network {
61 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
64 ##check if IP is in use
66 ##ping ip to get arp entry, then check arp
68 ping -c 5 $1 > /dev/null 2>&1
69 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
74 function next_usable_ip {
76 while [ "$new_ip" ]; do
77 if ! is_ip_used $new_ip; then
81 new_ip=$(next_ip $new_ip)
86 ##increment ip by value
87 ##params: ip, amount to increment by
88 ##increment_ip $next_private_ip 10
89 function increment_ip {
90 baseaddr="$(echo $1 | cut -d. -f1-3)"
91 lsv="$(echo $1 | cut -d. -f4)"
94 if [ "$lsv" -ge 254 ]; then
102 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
107 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
108 echo "Use -h to display help"
111 while [ "`echo $1 | cut -c1`" = "-" ]
136 if ! yum repolist | grep "epel/"; then
137 if ! rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm; then
138 printf '%s\n' 'deploy.sh: Unable to configure EPEL repo' >&2
142 printf '%s\n' 'deploy.sh: Skipping EPEL repo as it is already configured.'
145 ##install dependencies
146 if ! yum -y install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms; then
147 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
151 ##install VirtualBox repo
152 if cat /etc/*release | grep -i "Fedora release"; then
153 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
155 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
158 cat > /etc/yum.repos.d/virtualbox.repo << EOM
160 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
164 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
165 skip_if_unavailable = 1
170 if ! yum list installed | grep -i virtualbox; then
171 if ! yum -y install VirtualBox-4.3; then
172 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
177 ##install kmod-VirtualBox
178 if ! lsmod | grep vboxdrv; then
179 if ! sudo /etc/init.d/vboxdrv setup; then
180 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
184 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
188 if ! rpm -qa | grep vagrant; then
189 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
190 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
194 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
197 ##add centos 7 box to vagrant
198 if ! vagrant box list | grep chef/centos-7.0; then
199 if ! vagrant box add chef/centos-7.0 --provider virtualbox; then
200 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
204 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
207 ##install workaround for centos7
208 if ! vagrant plugin list | grep vagrant-centos7_fix; then
209 if ! vagrant plugin install vagrant-centos7_fix; then
210 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
213 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
218 ##remove bgs vagrant incase it wasn't cleaned up
219 rm -rf /tmp/bgs_vagrant
222 ##will change this to be opnfv repo when commit is done
223 if ! git clone https://github.com/trozet/bgs_vagrant.git; then
224 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
230 echo "${blue}Detecting network configuration...${reset}"
231 ##detect host 1 or 3 interface configuration
232 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
233 output=`ifconfig | grep -E "^[a-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet:" | awk '{print $1}' | sed 's/://'`
235 if [ ! "$output" ]; then
236 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
240 ##find number of interfaces with ip and substitute in VagrantFile
242 for interface in ${output}; do
244 if [ "$if_counter" -ge 4 ]; then
247 interface_ip=$(find_ip $interface)
248 if [ ! "$interface_ip" ]; then
251 new_ip=$(next_usable_ip $interface_ip)
252 if [ ! "$new_ip" ]; then
255 interface_ip_arr[$if_counter]=$new_ip
256 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\''/' Vagrantfile
260 ##now remove interface config in Vagrantfile for 1 node
261 ##if 1, 3, or 4 interfaces set deployment type
262 ##if 2 interfaces remove 2nd interface and set deployment type
263 if [ "$if_counter" == 1 ]; then
264 deployment_type="single_network"
265 remove_vagrant_network eth_replace1
266 remove_vagrant_network eth_replace2
267 remove_vagrant_network eth_replace3
268 elif [ "$if_counter" == 2 ]; then
269 deployment_type="single_network"
270 second_interface=`echo $output | awk '{print $2}'`
271 remove_vagrant_network $second_interface
272 remove_vagrant_network eth_replace2
273 elif [ "$if_counter" == 3 ]; then
274 deployment_type="three_network"
275 remove_vagrant_network eth_replace3
277 deployment_type="multi_network"
280 echo "${blue}Network detected: ${deployment_type}! ${reset}"
282 if route | grep default; then
283 defaultgw=$(route | grep default | awk '{print $2}')
284 echo "${blue}Default gateway detected: $defaultgw ${reset}"
285 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
287 defaultgw=`echo ${interface_arr_ip[0]} | cut -d. -f1-3`
289 defaultgw=$defaultgw$firstip
290 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
291 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
294 sed -i 's/^.*default_gw:.*$/default_gw:'" $defaultgw"'/' opnfv_ksgen_settings.yml
296 if [ $base_config ]; then
297 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
298 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
303 if [ $no_parse ]; then
304 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
308 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
309 ##Edit the ksgen settings appropriately
310 ##ksgen settings will be stored in /vagrant on the vagrant machine
311 ##if single node deployment all the variables will have the same ip
312 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
314 ##replace private interface parameter
315 ##private interface will be of hosts, so we need to know the provisioned host interface name
316 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
317 ##replace IP for parameters with next IP that will be given to controller
318 if [ "$deployment_type" == "single_network" ]; then
319 sed -i 's/^.*ovs_tunnel_if:.*$/ ovs_tunnel_if: eth0/' opnfv_ksgen_settings.yml
320 ##we also need to assign IP addresses to nodes
321 ##for single node, foreman is managing the single network, so we can't reserve them
322 ##not supporting single network anymore for now
323 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
326 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
327 sed -i 's/^.*ovs_tunnel_if:.*$/ ovs_tunnel_if: eth1/' opnfv_ksgen_settings.yml
329 if [ "$deployment_type" == "three_network" ]; then
330 sed -i 's/^.*storage_iface:.*$/ storage_iface: eth1/' opnfv_ksgen_settings.yml
331 sed -i 's/^.*network_type:.*$/ network_type: three_network/' opnfv_ksgen_settings.yml
333 sed -i 's/^.*storage_iface:.*$/ storage_iface: eth3/' opnfv_ksgen_settings.yml
336 ##get ip addresses for private network on controllers to make dhcp entries
337 ##required for controllers_ip_array global param
338 next_private_ip=${interface_ip_arr[1]}
340 for node in controller1 controller2 controller3; do
341 next_private_ip=$(next_usable_ip $next_private_ip)
342 if [ ! "$next_private_ip" ]; then
343 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
346 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
347 controller_ip_array=$controller_ip_array$next_private_ip,
350 ##replace global param for contollers_ip_array
351 controller_ip_array=${controller_ip_array%?}
352 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
354 ##now replace all the VIP variables. admin//private can be the same IP
355 ##we have to use IP's here that won't be allocated to hosts at provisioning time
356 ##therefore we increment the ip by 10 to make sure we have a safe buffer
357 next_private_ip=$(increment_ip $next_private_ip 10)
359 grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml | while read -r line ; do
360 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
361 next_private_ip=$(next_usable_ip $next_private_ip)
362 if [ ! "$next_private_ip" ]; then
363 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
368 ##replace public_vips
369 next_public_ip=${interface_ip_arr[2]}
370 next_public_ip=$(increment_ip $next_public_ip 10)
371 grep -E '*public_vip' opnfv_ksgen_settings.yml | while read -r line ; do
372 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
373 next_public_ip=$(next_usable_ip $next_public_ip)
374 if [ ! "$next_public_ip" ]; then
375 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
380 ##replace private_subnet param
382 baseaddr="$(echo $next_private_ip | cut -d. -f1-3)"
383 private_subnet=$baseaddr$network
384 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"''"\/24"'/' opnfv_ksgen_settings.yml
386 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
390 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
394 echo "${blue}Starting Vagrant! ${reset}"
397 if ! vagrant up; then
398 printf '%s\n' 'deploy.sh: Unable to start vagrant' >&2