Foreman provision to bare and libvirtd (Centos7, foreman, libvirtd, KVM)

So I have started to play around with foreman and to get it to provision my diffrent servers. I started by starting up some local virtual servers on my laptop and played around with them.

The flow is i started installing foreman as a virtual server. Then i provisin a new virtual server as bare matal (I created a virtual server in virsh) ater that virtual server is prevision i installed it as a virtual host(kvm on kvm) and connected it to foreman so foreman kan provision kvm host.

First is to get you local laptop / computer ready for the running all settings.

1. Laptop / host

 

In libvirt create a now network NAT but DISABLE DHCP settings in that network. my is 10.0.0.0/24 and the host has ip 10.0.0.1 for routing

 

Under processor set the “copy host CPU configuration” this must be set for kvm in kvm to work

 

2. Install Foreman

Start with setting upp a clean new virtual server and install centos7 on that server. Connect it to the new network you set up before and set it to 10.0.0.2/24 and gw 10.0.0.1 dns 10.0.0.1

Verify that the host has network connection

 

set the correct hostname and ip in /etc/hosts if you hostname is foreman and you domain example.com other we will have some problems

vi /etc/hosts
10.0.0.2 foreman.example.com

 

 

Now we can install foreman and i disable fw and selinux for now in my lab,

 

rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
yum -y install epel-release http://yum.theforeman.org/releases/1.7/el7/x86_64/foreman-release.rpm
yum -y install foreman-installer
foreman-installer --enable-foreman-proxy
systemctl stop firewalld
setenforce 0

 

Thats it now foreman shoule be installed and ready

 

3. Provision your first bare metal host (here its a virtual server that i create  :-))

There are some settings that needed to be done before setting it all uo.

1. under operattionsystem and CentOS7.1 under minor i have a 1 remove that so that box is empty (there are no centos mirror for /7/1 so it does not work)

2. go to infrastruktur / provision setup and fill in all the settings

Network

name:example.com
subnet
name:hostnet
network:10.0.0.0
mask:255.255.255.0
router:10.0.0.1
primary dns:10.0.0.2 <--ip to you foreman
secundary dns:10.0.0.3 <--- to ip not there
IPAM:DHCP
From:10.0.0.100
To:10.0.0.200
Boot mode:DHCP

foreman-installer

Now you will get some foreman-installer command to run. run the command WITH the DHCP config and run on foreman host.

 

my looke like this DO NOT RUN THIS ON YOUR FOREMAN

 

foreman-installer \
 --enable-foreman-proxy \
 --foreman-proxy-tftp=true \
 --foreman-proxy-tftp-servername=10.0.0.2 \
 --foreman-proxy-dhcp=true \
 --foreman-proxy-dhcp-interface=ens3 \
 --foreman-proxy-dhcp-gateway= \
 --foreman-proxy-dhcp-range="10.0.0.100 10.0.0.210" \
 --foreman-proxy-dhcp-nameservers="10.0.0.2" \
 --foreman-proxy-dns=true \
 --foreman-proxy-dns-interface=ens3 \
 --foreman-proxy-dns-zone=ollebo.com \
 --foreman-proxy-dns-reverse=0.0.10.in-addr.arpa \
 --foreman-proxy-dns-forwarders=10.0.0.1 \
 --foreman-proxy-foreman-base-url=https://forman.ollebo.com \
 --foreman-proxy-oauth-consumer-key=BPWNafbAMTEADEEf \
 --foreman-proxy-oauth-consumer-secret=3UwzrvN

 

Installation media
see that Centos mirror is enabled and click next

New Host

1. Start by creating a new virtual server on you laptop (The bare metal server to be install) make it to the network we created, Choose pxe installatio AND copy cpu settings. The rest you can choose fre

Now create a new bare metal host fill in you settings copy the mac from the virtual host you created.

Start you virtual machine and se it be installed and provision by foreman.

 

4. Setup foreman with KVM (libvirtd)

So we should now have a server running provision from foreman lets install kvm on it and ad it as a foreman resource.

 

In the provision server the new kvm host install kvm.

yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer

 

 

Turn selinux and firewalld of

systemctl stop firewalld
setenforce 0

 

destroy the default network

[root@generic ~]# virsh
Välkommen till virsh, den interaktiva terminalen för virtualisering.
Skriv: 'help' för hjälp med kommandon
 'quit' för att avsluta
virsh # net-destroy default
Nätverk default förstört
virsh # net-list
 Namn Tillstånd Autostart Persistent
----------------------------------------------------------

I connect to the host and with the virsh gui connect a new bridge network connected to the intreface connected to the host network we created on the virsh base host.

 

Foreman setup

Go to the foreman server and do the following to setup so that foreman has access to the new kvm host

root# su foreman -s /bin/bash 
foreman$ ssh-keygen 
foreman$ ssh-copy-id root@hostname.com 
foreman$ ssh root@hostname.com 
foreman$ virsh -c qemu+ssh://root@hypervisor.example.com/system list.
 Id Namn Tillstånd
----------------------------------------------------

 

Now we have a working connection between the formeman server an our kvm host

install foreman packages

yum install foreman-libvirt

reboot foreman server (some say it should work with onky restart foreman service but it did not work for me)

When foreman comes back up stop firewalld and setenforce to 0

 

Login into the foreman webbpage and go to “computer resource” and add new

name:kvm host
provider:Libvird
URL:qemu+ssh://root@10.0.0.104/system  CHANGE TO YOUR IP
Display type:VNC
Console Password:No

Now you have a new an libvird kvm provider ready and we can start provision out new host and choose our libvirtd host

 

 

 

5. when it does not work

 

– Verify that selinux and firewalld is off

– no pxe check /var/lib/tft/boot and the files there has any content I hade files that where blank. then download the new files from the centos mirrors and change there name to fit.

wget http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/initrd.img
wget http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/vmlinuz

– no kickstart well it can be your dns verify that the forman dns gives back the correct dns record

dig forman.examlpe.com @localhost