d0bba64526179482d4240f82e9bbf7793ec7aff7
[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 ##END VARS
22
23 ##set hostname
24 echo "${blue} Setting Hostname ${reset}"
25 hostnamectl set-hostname $host_name
26
27 ##remove NAT DNS
28 echo "${blue} Removing DNS server on first interface ${reset}"
29 if ! grep 'PEERDNS=no' /etc/sysconfig/network-scripts/ifcfg-enp0s3; then
30   echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-enp0s3
31   systemctl restart NetworkManager
32 fi
33
34 if ! ping www.google.com -c 5; then 
35   echo "${red} No internet connection, check your route and DNS setup ${reset}"
36   exit 1
37 fi
38
39 # Install EPEL repo for access to many other yum repos
40 # Major version is pinned to force some consistency for Arno
41 yum install -y epel-release-7*
42
43 # Update device-mapper-libs, needed for libvirtd on compute nodes
44 # Major version is pinned to force some consistency for Arno
45 if ! yum -y upgrade device-mapper-libs-1*; then
46    echo "${red} WARN: Unable to upgrade device-mapper-libs...nova-compute may not function ${reset}"
47 fi
48
49 # Install other required packages
50 # Major version is pinned to force some consistency for Arno
51 echo "${blue} Installing Puppet ${reset}"
52 if ! yum install -y puppet-3*; then
53   printf '%s\n' 'vm_nodes_provision.sh: failed to install required packages' >&2
54   exit 1
55 fi
56
57 echo "${blue} Configuring puppet ${reset}"
58 cat > /etc/puppet/puppet.conf << EOF
59
60 [main]
61 vardir = /var/lib/puppet
62 logdir = /var/log/puppet
63 rundir = /var/run/puppet
64 ssldir = \$vardir/ssl
65
66 [agent]
67 pluginsync      = true
68 report          = true
69 ignoreschedules = true
70 daemon          = false
71 ca_server       = foreman-server.opnfv.com
72 certname        = $host_name
73 environment     = production
74 server          = foreman-server.opnfv.com
75 runinterval     = 600
76
77 EOF
78
79 # Setup puppet to run on system reboot
80 /sbin/chkconfig --level 345 puppet on
81
82 /usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-server.opnfv.com --no-daemonize
83
84 sync
85
86 # Inform the build system that we are done.
87 echo "Informing Foreman that we are built"
88 wget -q -O /dev/null --no-check-certificate http://foreman-server.opnfv.com:80/unattended/built
89
90 echo "Starting puppet"
91 systemctl start puppet