Customise Foreman VM xml files

I want to be able to change the xml file Foreman uses to create a VM, specifically I’d like to add

As we only have the one Foreman setup, I’d like some way to do this selectively initially, so we can test it works as expected.

Expected outcome:
This enables the VM(s) in qn to access the underlying HW KVM for better cpu randomicity when random values are reqd.

Foreman and Proxy versions:
1.14 Foreman

Foreman and Proxy plugin versions:

Distribution and version:
Centos 7.7

Other relevant data:

Hello and welcome,

Foreman uses this library to do libvirt management and XML files are hardcoded in there:

Feel free to edit those templates there, or add a parameter to the API which allows you to do what you need.

Sidenote: We do not recommend using libvirt for production use, use oVirt (which is based on libvirt but scalable) or other platforms like VMWare instead.

Hi lzap,

thanks for the reply; sorry for the delay.

I’m probably missing something here, but afaict, there is only one(!) server.xml.erb under …/templates/.
I can’t see how to produce and access another version.
(I’ve only ever used Foreman; never tried to alter it)

As above, we only have one Foreman setup and we need to be able to add this change

  <cpu mode='host-model'>
    <model fallback='allow'/>

to any specified VM, without affecting normal VM creations.

In other words, I’d like to be able to ‘template’ it but the Foreman GUI only seems to offer the ability to template at a higher level ie OS creation.

Apologies if this is badly phrased - I’m not clear on the exact terminology.


I understand, however we are not planning such feature. Feel free to contribute if that does not make the workflow too complex tho.

That’s a real shame.

I’m afraid I couldn’t add that functionality myself - I don’t have the relevant tech skills.

Thanks anyway - good to have a definite answer.


Well you can always patch the ERB file in fog-libvirt if that’s ok to have for all VMs created via Foreman.

One more recommendtation, we put most resources into oVirt integration, that’s basically libvirt with API and UI. Take a look if you can deploy that instead, we do not recommend libvirt for production use, you can’t do many enterprise things without serious effort (e.g. live migrations etc).

I suspect that Feature #2308: Expose interface to "Copy Host CPU configuration" - Foreman actually solves your need but you’re on an ancient 1.14 installation. I’d start with updating and see if you still have the same problem. The ticket/code suggests 1.21 has the feature but I’d suggest a supported version (1.24 / 2.0 right now).

That’s what I was trying to avoid :slight_smile: , hence the qn.
This is for a fleet of commercial systems (~ 2000) so i really wanted to test it selectively first.
However, it looks like we are going to go for it…

oVirt: We may look into that.
The request I had was just about the cpu rand thing, but as it happens we are looking to do a major upgrade to v2.0 anyway - I’m probably going to be working with the guy in charge of that proj.

ekohl : That sounds interesting, but having looked at that link, i don’t see how that would be exposed on the GUI

To either of you (or anyone):
Apparently the last time someone tried to upgrade us past foreman v1.14.3, it had trouble talking to libvirt on Centos 6.
Is that a known issue? Have you got any info/tips?
(Yes, we are looking to replace all C6 systems, but that’s non-trivial in a large commercial setup)


You can do “if hostname =~ /^test-/” kind of hack :slight_smile:

Honestly, you are not the first one asking for this, but the way fog is designed editing full ERB would probably be tought to implement. What you can actually do pretty well is add a new flag into fog that sets the value you need and modify ERB to do that. Or if you really need brand new template, add a flag called “base template” or whatever which selects one of predefined. But I would suggest rather sticking with one template and extending it.

With so many VMs, I wonder how you do things like live migrations, shared storage or networking. This can be tricky to do with libvirt, you are on your own. oVirt can handle this for you pretty well.

We probably haven’t fixed that, you need to test. I remember one bug I was working in that regard but cannot find it on our Redmine.

I am not surprised - it did seem a bit odd you can’t (easily) have different HW “options” (aka templates).
Otoh, it is the sort of thing that is best designed-in early on, not hacked on later.

Thx for the replies anyway.