Merge "Remove Compass from genesis."
[genesis.git] / opensteak / tools / templates_foreman / install.sh
1 #!/bin/sh
2 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14 #
15 # Authors:
16 # @author: David Blaisonneau <david.blaisonneau@orange.com>
17 # @author: Arnaud Morin <arnaud1.morin@orange.com>
18
19 ### Set vars
20 NAME="${name}"
21 DOMAIN="${domain}"
22 DATEE=$$(date +%F-%Hh%M)
23 IP="${ip}"
24 MASK="${netmaskshort}"
25 NET="${network}"
26 DHCP_RANGE="${dhcprange}"
27 REVERSE_DNS="${reversedns}"
28 DNS_FORWARDER="${dns}"
29 ADMIN="${admin}"
30 PASSWORD="${password}"
31
32 ### Set correct env
33 #dpkg-reconfigure locales
34 export LC_CTYPE=en_US.UTF-8
35 export LANG=en_US.UTF-8
36 unset LC_ALL
37 umask 0022
38
39 ### Check hostname is on the public interface
40 echo "* Ensure hostname point to external IP"
41 # Remove useless lines
42 perl -i -pe 's/^127.0.1.1.*\n$$//' /etc/hosts
43 perl -i -pe "s/^$${IP}.*\n$$//" /etc/hosts
44 # Append a line
45 echo "$${IP} $${NAME}.$${DOMAIN} $${NAME}" >> /etc/hosts
46
47 ### Dependencies
48 echo "* Install dependencies"
49 apt-get -y install ca-certificates wget git isc-dhcp-server
50
51 ### Set AppArmor
52 echo "* Set App armor"
53 cat /etc/apparmor.d/local/usr.sbin.dhcpd | grep '/etc/bind/rndc.key r,' >/dev/null
54 if [ $$? -eq 1 ] ; then
55     echo "/etc/bind/rndc.key r," >> /etc/apparmor.d/local/usr.sbin.dhcpd
56 fi
57
58 ### Prepare repos
59 echo "* Enable Puppet labs repo"
60 if [ "Z" = "Z$$(dpkg -l |grep 'ii  puppetlabs-release')" ] ; then
61     wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb
62     dpkg -i puppetlabs-release-trusty.deb
63     apt-get update
64 fi
65
66 # Install puppetmaster
67 echo "* Install puppetmaster"
68 if [ "Z" = "Z$$(dpkg -l |grep 'ii  puppetmaster')" ] ; then
69     apt-get -y install puppetmaster
70 fi
71
72 # Enable the Foreman repo
73 echo "* Enable Foreman repo"
74 if [ ! -e /etc/apt/sources.list.d/foreman.list ] ; then
75     echo "deb http://deb.theforeman.org/ trusty 1.8" > /etc/apt/sources.list.d/foreman.list
76     echo "deb http://deb.theforeman.org/ plugins 1.8" >> /etc/apt/sources.list.d/foreman.list
77     wget -q http://deb.theforeman.org/pubkey.gpg -O- | apt-key add -
78     apt-get update
79 fi
80
81 ### Install Foreman
82 echo "* Install foreman-installer"
83 if [ "Z" = "Z$$(dpkg -l |grep 'ii  foreman-installer')" ] ; then
84     apt-get -y install foreman-installer
85 fi
86 if [ "Z" = "Z$$(gem list --local |grep rubyipmi)" ] ; then
87     gem install -q rubyipmi
88 fi
89
90 ### Execute foreman installer
91 echo "* Execute foreman installer"
92
93 foreman-installer \
94  --foreman-admin-username="$$ADMIN" \
95  --foreman-admin-password="$$PASSWORD" \
96  --enable-foreman-plugin-templates \
97  --enable-foreman-plugin-discovery \
98  --foreman-plugin-discovery-install-images=true \
99  --enable-foreman-compute-libvirt
100
101
102 foreman-installer \
103  --foreman-admin-username="$$ADMIN" \
104  --foreman-admin-password="$$PASSWORD" \
105  --enable-foreman-plugin-templates \
106  --enable-foreman-plugin-discovery \
107  --foreman-plugin-discovery-install-images=true \
108  --enable-foreman-compute-libvirt \
109  --enable-foreman-proxy \
110  --foreman-proxy-bmc=true \
111  --foreman-proxy-tftp=true \
112  --foreman-proxy-tftp-servername="$$IP" \
113  --foreman-proxy-dhcp=true \
114  --foreman-proxy-dhcp-interface="eth0" \
115  --foreman-proxy-dhcp-gateway="$$IP" \
116  --foreman-proxy-dhcp-range="$$DHCP_RANGE" \
117  --foreman-proxy-dhcp-nameservers="$$IP" \
118  --foreman-proxy-dns=true \
119  --foreman-proxy-dns-interface="eth0" \
120  --foreman-proxy-dns-zone="$$DOMAIN" \
121  --foreman-proxy-dns-reverse="$$REVERSE_DNS" \
122  --foreman-proxy-dns-forwarders="$$DNS_FORWARDER" \
123  --foreman-proxy-foreman-base-url="https://localhost"
124
125 ### Sync community templates for last ubuntu versions
126
127 echo "* Sync community templates for last ubuntu versions"
128 foreman-rake templates:sync
129
130 ### Get and install OpenSteak files
131
132 echo "* Get OpenSteak repos"
133 if [ -d /usr/local/opensteak ] ; then
134     cd /usr/local/opensteak
135     git pull
136 else
137     cd /usr/local/
138     git clone https://github.com/Orange-OpenSource/opnfv.git -b foreman opensteak
139 fi
140 cd /usr/local/opensteak/infra/puppet_master
141
142 echo "* Set puppet auth"
143 echo "*.$$DOMAIN" > /etc/puppet/autosign.conf
144 if [ -e /etc/puppet/auth.conf ] ; then
145   # Make a backup
146   mv /etc/puppet/auth.conf /etc/puppet/auth.conf.$$DATEE
147 fi
148 cp etc/puppet/auth.conf /etc/puppet/auth.conf
149 perl -i -pe "s/__NET__/$$NET/" /etc/puppet/auth.conf
150 perl -i -pe "s/__MASK__/$$MASK/" /etc/puppet/auth.conf
151
152 # Set Hiera Conf
153 echo "* Push Hiera conf into /etc/puppet/"
154 if [ -e /etc/puppet/hiera.yaml ] ; then
155   # Make a backup
156   mv /etc/puppet/hiera.yaml /etc/puppet/hiera.yaml.$$DATEE
157 fi
158 cp etc/puppet/hiera.yaml /etc/puppet/hiera.yaml
159 if [ -e /etc/hiera.yaml ] ; then
160   rm /etc/hiera.yaml
161 fi
162 ln -s /etc/puppet/hiera.yaml /etc/hiera.yaml
163 cp -rf etc/puppet/hieradata /etc/puppet/
164 rename s/DOMAIN/$$DOMAIN/ /etc/puppet/hieradata/production/nodes/*.yaml
165 cp etc/puppet/manifests/site.pp /etc/puppet/manifests/site.pp
166 cp ../config/common.yaml /etc/puppet/hieradata/production/common.yaml
167 chgrp puppet /etc/puppet/hieradata/production/*.yaml
168
169 # Install and config r10k
170 echo "* Install and setup r10k"
171 if [ "Z" = "Z$$(gem list --local |grep r10k)" ] ; then
172     gem install -q r10k
173 fi
174 if [ -e /etc/r10k.yaml ] ; then
175   # Make a backup
176   mv /etc/r10k.yaml /etc/r10k.yaml.$$DATEE
177 fi
178 cp etc/r10k.yaml /etc/r10k.yaml
179
180 # Install opensteak-r10k-update script
181 echo "* Install opensteak-r10k-update script into /usr/local/bin"
182 cp usr/local/bin/opensteak-r10k-update /usr/local/bin/opensteak-r10k-update
183 chmod +x /usr/local/bin/opensteak-r10k-update
184
185 echo "* Run R10k. You can re-run r10k by calling:"
186 echo "   opensteak-r10k-update"
187 opensteak-r10k-update
188
189 #### Install VIM puppet
190 echo "* Install VIM puppet"
191 if [ ! -d ~/.vim/autoload ] ; then
192   mkdir -p ~/.vim/autoload
193 fi
194 if [ ! -d ~/.vim/bundle ] ; then
195   mkdir -p ~/.vim/bundle
196 fi
197 curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
198 cat <<EOF > ~/.vimrc
199 execute pathogen#infect()
200 syntax on
201 filetype plugin indent on
202 EOF
203 cd ~/.vim/bundle
204 if [ ! -d vim-puppet ] ; then
205   git clone https://github.com/rodjek/vim-puppet.git > /dev/null
206 fi
207
208 ### Gen SSH key for foreman
209 echo "* SSH Key"
210 cp /mnt/id_rsa /usr/share/foreman/.ssh/
211 cp /mnt/id_rsa.pub /usr/share/foreman/.ssh/
212 chown foreman:foreman /usr/share/foreman/.ssh/ -R
213
214 ### Run puppet
215 puppet agent -t -v
216