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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
16 # @author: David Blaisonneau <david.blaisonneau@orange.com>
17 # @author: Arnaud Morin <arnaud1.morin@orange.com>
22 DATEE=$$(date +%F-%Hh%M)
24 MASK="${netmaskshort}"
26 DHCP_RANGE="${dhcprange}"
27 REVERSE_DNS="${reversedns}"
28 DNS_FORWARDER="${dns}"
30 PASSWORD="${password}"
33 #dpkg-reconfigure locales
34 export LC_CTYPE=en_US.UTF-8
35 export LANG=en_US.UTF-8
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
45 echo "$${IP} $${NAME}.$${DOMAIN} $${NAME}" >> /etc/hosts
48 echo "* Install dependencies"
49 apt-get -y install ca-certificates wget git isc-dhcp-server
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
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
66 # Install puppetmaster
67 echo "* Install puppetmaster"
68 if [ "Z" = "Z$$(dpkg -l |grep 'ii puppetmaster')" ] ; then
69 apt-get -y install puppetmaster
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 -
82 echo "* Install foreman-installer"
83 if [ "Z" = "Z$$(dpkg -l |grep 'ii foreman-installer')" ] ; then
84 apt-get -y install foreman-installer
86 if [ "Z" = "Z$$(gem list --local |grep rubyipmi)" ] ; then
87 gem install -q rubyipmi
90 ### Execute foreman installer
91 echo "* Execute 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
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"
125 ### Sync community templates for last ubuntu versions
127 echo "* Sync community templates for last ubuntu versions"
128 foreman-rake templates:sync
130 ### Get and install OpenSteak files
132 echo "* Get OpenSteak repos"
133 if [ -d /usr/local/opensteak ] ; then
134 cd /usr/local/opensteak
138 git clone https://github.com/Orange-OpenSource/opnfv.git -b foreman opensteak
140 cd /usr/local/opensteak/infra/puppet_master
142 echo "* Set puppet auth"
143 echo "*.$$DOMAIN" > /etc/puppet/autosign.conf
144 if [ -e /etc/puppet/auth.conf ] ; then
146 mv /etc/puppet/auth.conf /etc/puppet/auth.conf.$$DATEE
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
153 echo "* Push Hiera conf into /etc/puppet/"
154 if [ -e /etc/puppet/hiera.yaml ] ; then
156 mv /etc/puppet/hiera.yaml /etc/puppet/hiera.yaml.$$DATEE
158 cp etc/puppet/hiera.yaml /etc/puppet/hiera.yaml
159 if [ -e /etc/hiera.yaml ] ; then
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
169 # Install and config r10k
170 echo "* Install and setup r10k"
171 if [ "Z" = "Z$$(gem list --local |grep r10k)" ] ; then
174 if [ -e /etc/r10k.yaml ] ; then
176 mv /etc/r10k.yaml /etc/r10k.yaml.$$DATEE
178 cp etc/r10k.yaml /etc/r10k.yaml
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
185 echo "* Run R10k. You can re-run r10k by calling:"
186 echo " opensteak-r10k-update"
187 opensteak-r10k-update
189 #### Install VIM puppet
190 echo "* Install VIM puppet"
191 if [ ! -d ~/.vim/autoload ] ; then
192 mkdir -p ~/.vim/autoload
194 if [ ! -d ~/.vim/bundle ] ; then
195 mkdir -p ~/.vim/bundle
197 curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
199 execute pathogen#infect()
201 filetype plugin indent on
204 if [ ! -d vim-puppet ] ; then
205 git clone https://github.com/rodjek/vim-puppet.git > /dev/null
208 ### Gen SSH key for foreman
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