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