Why does foreman support only one provisioning template per operating system?

Hello together,

i have a question about the architecture design of foreman, wich i dont
understand from a users perspective.
Why does foreman support only one provisioning user data template per
operating system? I dont really understand the benefit from this, because i
have some scenarios in my head, where it could be useful while provisioning
a new host to chooese between different user data templates. I want to give
two simple scenarios:

  1. I want to provisioning image based from a vmware template per
    foreman-vmware with a user data template. So maybe i want
    sometimes provisioning a host without static ip configuration and other
    times i want to provisioning with a static ip configuration. In this
    screnario i always have to edit the adapter settings in the user data
    template before i go to create a new host. Because if i have adapter
    settings in the user data template who expect ip adresses and so on,
    the provisioning process over vmware will fail if iam not providing this in
    foreman. If i want the host just get a random ip adress from the dhcp
    server and dont set it static, i have to kick the static adapter settings
    out of the user data template before creating a new host.

  2. Another thing is, if i have multiple environments. I install over the
    user data template for example over powershell command the windows puppet
    agent. Also define there in wich environment i want to provisioning over
    installation arguments from the puppet agent msi file. So that meens that i
    always have to edit the user data template when i want to change the
    environment before creating a new host. Because in the new host dialouge i
    can choose the environment, but the agent dosent care and always use
    "production" if i didnt provide other environments over installation
    arguments.

Like this i think its very unlucky, especially if you work with more users
on the same foreman master server and they all want to provisioning
different hosts with different needs in different environments.

For me it would be the best if i just choose in the "new host"-dialogue
image based provisioning" and after i choose my operating system and click
on "resolve" he return me a list of different user data templates for my
needs and not only always one. So that every user can chooese what they
need at that moment.

I cant really imagen that iam the only one who has this "problem", maybe
its because i dont understand the design architecture of foreman. So i want
to ask here, why its designed like this?

Thanks in advance

Hi there,

> Hello together,
>
> i have a question about the architecture design of foreman, wich i
> dont understand from a users perspective.
> Why does foreman support only one provisioning user data template per
> operating system? I dont really understand the benefit from this,
> because i have some scenarios in my head, where it could be useful
> while provisioning a new host to chooese between different user data
> templates.

It is possible to have multiple templates for an OS. The choice on the
OS edit page simple sets the default one. However, it's not
immediately obvious, so you can be forgiven for missing it :wink:

If you go to a particular template, and go to the Association tab,
after you've assigned the appropriate OSs to the template you'll see a
button marked "Valid host group and environment combinations". This
alows you to specify conditions for matching this template to a host,
based on Hostgroup and/or Environment.

Thus you could have:

  • Preseed default - default in the OS page
  • Preseed (Production) - matched if env == production
  • Preseed (Webservers) - matched if production and in the Web group

and so on. This gives you flexibilty to choose templates based on the
needs of your individual hosts - just put them into a specific group or
env and click Resolve Templates to check it matched.

> I want to give two simple scenarios:
>
> 1. I want to provisioning image based from a vmware template per
> foreman-vmware with a user data template. So maybe i want
> sometimes provisioning a host without static ip configuration and
> other times i want to provisioning with a static ip configuration. In
> this screnario i always have to edit the adapter settings in the user
> data template before i go to create a new host. Because if i have
> adapter settings in the user data template who expect ip adresses and
> so on, the provisioning process over vmware will fail if iam not
> providing this in foreman. If i want the host just get a random ip
> adress from the dhcp server and dont set it static, i have to kick
> the static adapter settings out of the user data template before
> creating a new host.

In addition to multiple templates, you can always use ERB to add
conditionals to templates, based on host parameters:

<% if @host.params['staic-ip'] == 'yup' %>
do static stuff
<% end %>

Which allows your users to add little bits on an opt-in basis (I think
our default netowrking templates already have an option for static
IPs). You could also use configuration management to do most of the big
changes once the host is provisioned.

  1. Another thing is, if i have multiple environments. I install over
    > the user data template for example over powershell command the
    > windows puppet agent. Also define there in wich environment i want
    > to provisioning over installation arguments from the puppet agent msi
    > file. So that meens that i always have to edit the user data template
    > when i want to change the environment before creating a new host.
    > Because in the new host dialouge i can choose the environment, but
    > the agent dosent care and always use "production" if i didnt provide
    > other environments over installation arguments.

Again, you want to use ERB to provide this kind of data, our default
templates do this for you (see https://github.com/theforeman/community-
templates/blob/develop/provisioning_templates/snippet/puppet.conf.erb#L
47 for how we set the environment).

> For me it would be the best if i just choose in the "new host"-
> dialogue image based provisioning" and after i choose my operating
> system and click on "resolve" he return me a list of different user
> data templates for my needs and not only always one. So that every
> user can chooese what they need at that moment.

The main answer here is that the Host new/edit page is waaay too
complicated already, and adding more selectors won't help. It'd be
lovely to redesign it, if there was time :slight_smile:

Greg

··· On Wed, 2017-05-24 at 09:02 -0700, nokrite wrote:

Hello Greg,

finally, i solve the problem. It seems a lower/uppercase conflict.

Thank you for your posting. This helps me a lot.

Best Regards

Good morning Greg,

first thanks for your answer.
That would change everything and i really didnt know that.

But iam honest, it still does not work for me.

I have two provisioning templates (user data templates) for one operation
system wich are associated with the operating system and the environment
where i want to use it.
But in the Operating System definition in the tab 'Templates' i have to
choose one user data template? If i left this empty, foreman does not
recognize any template while creating a new host ? This have also the "*"
marked that meen i have provide their one user data template for default
and this is exaclty the user data template he use always, no matter wich
hostgroup or environment i have associated.for different user data
templates.

In the screens of the attachment shows what i do when keeping the "user
data template" tab empty (2nd screen).
If i keep it not empty and chooese there one for default, he always
resolves the default template not matter wich environment i choose. I have
associated both user data templates you see in 2nd screen associated with
different environemts. I did it as you see in screen 1.
It does not have any affect if i set also there a specific hostgroup.

Are you so kind to tell me what iam doing wrong? That would be great.

Thank you so or so.

Best Regards

··· Am Donnerstag, 25. Mai 2017 11:23:44 UTC+2 schrieb Greg Sutcliffe: > > It is possible to have multiple templates for an OS. The choice on the > OS edit page simple sets the *default* one. However, it's not > immediately obvious, so you can be forgiven for missing it ;) > > If you go to a particular template, and go to the Association tab, > after you've assigned the appropriate OSs to the template you'll see a > button marked "Valid host group and environment combinations". This > alows you to specify conditions for matching this template to a host, > based on Hostgroup and/or Environment. > > Thus you could have: > > * Preseed default - default in the OS page > * Preseed (Production) - matched if env == production > * Preseed (Webservers) - matched if production and in the Web group > > and so on. This gives you flexibilty to choose templates based on the > needs of your individual hosts - just put them into a specific group or > env and click Resolve Templates to check it matched. >

I’m having the same issue.
I have 2 different platforms (1. VM; 2. bare metal server) installing the same OS but have 2 different disk targets (sda and sdd respectively). I would have created a second Operating System but Foreman doesn’t let me reuse the URL for the repository.
How can use 2 templates or parametrize the provisioning template to take a different kickstart file depending on the Host Group?

I believe you resurrected quite an old thread here. Basically, what you want to do is to customize the provisioning templates. You can use that technique for both for a provisioning template or a partition table.
The templates allow you to do basically anything. Let me give you some examples that you can adapt to your needs.

<%= @host.hostgroup.name == 'My Hostgroup for BareMetal' ? 'sda' : 'sdb' %>

Or something like this:

<% if @host.compute? %>
This line is rendered when the host is a VM.
<% else %>
This line is rendered when the host is bare metal.
<% end %>