Copy Foreman deploy logic from bgs_vagrant repo
[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
40 if ! yum repolist | grep "epel/"; then
41   if ! rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm; then
42     printf '%s\n' 'vm_provision_nodes.sh: Unable to configure EPEL repo' >&2
43     exit 1
44   fi
45 else
46   printf '%s\n' 'vm_nodes_provision.sh: Skipping EPEL repo as it is already configured.'
47 fi
48
49 ##install device-mapper-libs
50 ##needed for libvirtd on compute nodes
51 if ! yum -y upgrade device-mapper-libs; then
52    echo "${red} WARN: Unable to upgrade device-mapper-libs...nova-compute may not function ${reset}"
53 fi
54
55 echo "${blue} Installing Puppet ${reset}"
56 ##install puppet
57 if ! yum list installed | grep -i puppet; then
58   if ! yum -y install puppet; then
59     printf '%s\n' 'vm_nodes_provision.sh: Unable to install puppet package' >&2
60     exit 1
61   fi
62 fi
63
64 echo "${blue} Configuring puppet ${reset}"
65 cat > /etc/puppet/puppet.conf << EOF
66
67 [main]
68 vardir = /var/lib/puppet
69 logdir = /var/log/puppet
70 rundir = /var/run/puppet
71 ssldir = \$vardir/ssl
72
73 [agent]
74 pluginsync      = true
75 report          = true
76 ignoreschedules = true
77 daemon          = false
78 ca_server       = foreman-server.opnfv.com
79 certname        = $host_name
80 environment     = production
81 server          = foreman-server.opnfv.com
82 runinterval     = 600
83
84 EOF
85
86 # Setup puppet to run on system reboot
87 /sbin/chkconfig --level 345 puppet on
88
89 /usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-server.opnfv.com --no-daemonize
90
91 sync
92
93 # Inform the build system that we are done.
94 echo "Informing Foreman that we are built"
95 wget -q -O /dev/null --no-check-certificate http://foreman-server.opnfv.com:80/unattended/built
96
97 echo "Starting puppet"
98 systemctl start puppet