Partition Table Template Variables

Posted on

I am trying to combine 2 Partition Templates into a single template with some if statements depending on which hostgroup a server is in. This is because our with our on-prem VM farm I configure swap, while with Azure the swap partition is not required as it added later and managed by Azure.

So currently I have an Azure template and and On-Prem template.

To split I have created nested hostgroups:

This is repeated for DEV/UAT/PRD and for RHEL8 again.

Using variables in the template I can only reference the child, e.g "DEV". But I would like to actually reference "HG_AZURE" and "HG_ONPREM"

<% hostgroup = @host.hostgroup %>
<% if == "DEV" %>
logvol swap --vgname=vg_root --name=lv_swap --size=5120
<% end %>

Have tried various options and they all work for DEV

<% if "DEV" %>
<% if["DEV"] %>

Unsurprisingly, when I try to slip in HG_AZURE / HG_ONPREM nothing happens. I would like to reference the parent of DEV. I have tried searching for how to address the different variables. The only page of any use has been various versions of TEMPLATE WRITING REFERENCE
And certainly the later versions are getting better, but I still can't figure out how to reference the "parent" hostgroups rather than the child.

I have also used, the subnet and might have to go with that, but for cleanness I would like to use "AZURE" or "ON_PREM" and the only place I've defined that is with the hostgroups.

Maybe there is another way to achieve this maybe with some type of variable applied to specific hosts/hostgroups which I could then reference.