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 and the host has ip 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 and gw dns

Verify that the host has network connection


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

vi /etc/hosts



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


rpm -ivh
yum -y install epel-release
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

primary dns: <--ip to you foreman
secundary dns: <--- to ip not there
Boot mode:DHCP


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= \
 --foreman-proxy-dhcp=true \
 --foreman-proxy-dhcp-interface=ens3 \
 --foreman-proxy-dhcp-gateway= \
 --foreman-proxy-dhcp-range="" \
 --foreman-proxy-dhcp-nameservers="" \
 --foreman-proxy-dns=true \
 --foreman-proxy-dns-interface=ens3 \ \ \
 --foreman-proxy-dns-forwarders= \
 --foreman-proxy-foreman-base-url= \
 --foreman-proxy-oauth-consumer-key=BPWNafbAMTEADEEf \


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 
foreman$ ssh 
foreman$ virsh -c qemu+ssh:// 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
URL:qemu+ssh://root@  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.


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

dig @localhost