e64c0ad787d5a3f73b8d526b3dc644a373a8dc0f
[genesis.git] / foreman / ci / vm_nodes_provision.sh
1 #!/usr/bin/env bash
2
3 #bootstrap script for VM OPNFV nodes
4 #author: Tim Rozet (trozet@redhat.com)
5 #
6 #Uses Vagrant and VirtualBox
7 #VagrantFile uses vm_nodes_provision.sh which configures linux on nodes
8 #Depends on Foreman being up to be able to register and apply puppet
9 #
10 #Pre-requisties:
11 #Target system should be Centos7 Vagrant VM
12
13 ##VARS
14 reset=`tput sgr0`
15 blue=`tput setaf 4`
16 red=`tput setaf 1`
17 green=`tput setaf 2`
18
19 host_name=REPLACE
20 dns_server=REPLACE
21 host_ip=REPLACE
22 ##END VARS
23
24 ##set hostname
25 echo "${blue} Setting Hostname ${reset}"
26 hostnamectl set-hostname $host_name
27
28 ##remove NAT DNS
29 echo "${blue} Removing DNS server on first interface ${reset}"
30 if ! grep 'PEERDNS=no' /etc/sysconfig/network-scripts/ifcfg-enp0s3; then
31   echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-enp0s3
32   systemctl restart NetworkManager
33 fi
34
35 ##modify /etc/resolv.conf to point to foreman
36 echo "${blue} Configuring resolv.conf with DNS: $dns_server ${reset}"
37 cat > /etc/resolv.conf << EOF
38 search ci.com opnfv.com
39 nameserver $dns_server
40 nameserver 8.8.8.8
41
42 EOF
43
44 ##modify /etc/hosts to add own IP for rabbitmq workaround
45 host_short_name=`echo $host_name | cut -d . -f 1`
46 echo "${blue} Configuring hosts with: $host_name $host_ip ${reset}"
47 cat > /etc/hosts << EOF
48 $host_ip  $host_short_name $host_name
49 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
50 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
51 EOF
52
53 if ! ping www.google.com -c 5; then
54   echo "${red} No internet connection, check your route and DNS setup ${reset}"
55   exit 1
56 fi
57
58 ##install EPEL
59 if ! yum repolist | grep "epel/"; then
60   if ! rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm; then
61     printf '%s\n' 'vm_provision_nodes.sh: Unable to configure EPEL repo' >&2
62     exit 1
63   fi
64 else
65   printf '%s\n' 'vm_nodes_provision.sh: Skipping EPEL repo as it is already configured.'
66 fi
67
68 ##install device-mapper-libs
69 ##needed for libvirtd on compute nodes
70 if ! yum -y upgrade device-mapper-libs; then
71    echo "${red} WARN: Unable to upgrade device-mapper-libs...nova-compute may not function ${reset}"
72 fi
73
74 echo "${blue} Installing Puppet ${reset}"
75 ##install puppet
76 if ! yum list installed | grep -i puppet; then
77   if ! yum -y install puppet; then
78     printf '%s\n' 'vm_nodes_provision.sh: Unable to install puppet package' >&2
79     exit 1
80   fi
81 fi
82
83 echo "${blue} Configuring puppet ${reset}"
84 cat > /etc/puppet/puppet.conf << EOF
85
86 [main]
87 vardir = /var/lib/puppet
88 logdir = /var/log/puppet
89 rundir = /var/run/puppet
90 ssldir = \$vardir/ssl
91
92 [agent]
93 pluginsync      = true
94 report          = true
95 ignoreschedules = true
96 daemon          = false
97 ca_server       = foreman-server.opnfv.com
98 certname        = $host_name
99 environment     = production
100 server          = foreman-server.opnfv.com
101 runinterval     = 600
102
103 EOF
104
105 # Setup puppet to run on system reboot
106 /sbin/chkconfig --level 345 puppet on
107
108 /usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-server.opnfv.com --no-daemonize
109
110 sync
111
112 # Inform the build system that we are done.
113 echo "Informing Foreman that we are built"
114 wget -q -O /dev/null --no-check-certificate http://foreman-server.opnfv.com:80/unattended/built
115
116 echo "Starting puppet"
117 systemctl start puppet