Foreman Template writing

Foreman uses common ERB style templating. Foreman templates consists of a mixture of Bash scripts and appropriate macros and functions. You can find a list of built-in macros and functions here. Within such macro you can use further Ruby code. For example to extract the last digits og an IP address you can use the following macro:

LAST_DIGIT=< %=@host.ip.to_s.split('.')[-1]%>

Where @host.ip is a built-in macro in Foreman (see link above), to_s is Ruby code and means “convert into string”, split wherever you find a “.” and read the output reverse and take the last value (“-1”).

If you want to check if a template will render correctly for an appropriate host you can open your template in your browser:

https:///unattended/provision?spoof='ip-of-a-host-you-want-to-provision'

2 thoughts on “Foreman Template writing

  1. Pooja

    What does each foreman templates does?????
    I know that it is specific to particular OS…..
    Not understanding what each templates does…
    I am new to foreman

    1. freimer Post author

      Hi Pooja, Foreman comes with a bunch of so called provisioning templates which will be rendered during the host installation via (i)PXE. The default kickstart template e.g. is working with parameters you can set before instaslling a host like hostname etc. You can also include other templates in one template. If specific parameters are set e.g. a FreeIPA client configuration will be performed during the host installation. You can also put static content to the templates like which packages should be installed during the host installation. The Foreman templates are very flexible.

Comments are closed.