Global parameters in templates


I’m looking for a way to use Global Parameters in provisioning templates? Is this possible?

I didn’t find any relevant documentation about that.

Thanks in advance.

AFAIK we do this all the time and it should just work.

It is slightly confusing, but to do that, you need to use host_param macro. Parameters go through inheritance chain, so default value comes from global parameter, then you can override those values on organization, location, domain, subnet, os, hostgroup, host level (in this order).

let’s imagine you have global parameter with name dns_server and you don’t define any other parameter, e.g. on OS with the same name.

<%= host_param('dns_server') %>

This renders the value inheritied from Global parameter. If you create a parameter with the same name e.g. on Location object, if the host belongs to that Location, it will win and the value will be taken from Location parameter. If the host does not belong to this Location, value from Global parameter still wins.

For the record, this is the weight of each parameter type (taken from the code base)

  PRIORITY = { :common_parameter => 0,
               :organization_parameter => 10,
               :location_parameter => 20,
               :domain_parameter => 30,
               :subnet_parameter => 40,
               :os_parameter => 50,
               :group_parameter => 60,
               :host_parameter => 70,

The current limitation is, you can’t access original Global parameter value if it’s overriden by some other parameter, e.g. specific value for the Host or the Location, like explained above. So far there was no need for that, however adding a macro to allow this is very simple. You could workaround that by disabling the SafeMode rendering and use something like this:

<%= CommonParameter.find_by_name('dns_server').value %>

Hope this helpls