TemplateWriting » History » Version 16
Justin Sherrill, 02/02/2011 11:37 AM
1 | 1 | Justin Sherrill | h1. Templates |
---|---|---|---|
2 | |||
3 | |||
4 | |||
5 | 16 | Justin Sherrill | The following functions and macros can be used within templates. These are guaranteed to work via the safemode rendering, to ensure a template can do nothing harmful. With safemode disabled other macros may work, but are not supported at this time. |
6 | 15 | Justin Sherrill | |
7 | To ensure that safemode is enabled, set ":safemode_render = true" in settings.yml. Safemode rendering prevents templates from reading and writing files on the file system or modifying application data within foreman. |
||
8 | 1 | Justin Sherrill | |
9 | |||
10 | 8 | Justin Sherrill | h2. Accessing Templates |
11 | 1 | Justin Sherrill | |
12 | 10 | Justin Sherrill | There are two ways to render a template, based on a single host, or based on a Hostgroup. The host or hostgroup provides all the details with which to render the template. |
13 | 1 | Justin Sherrill | |
14 | 10 | Justin Sherrill | |
15 | 8 | Justin Sherrill | h3. Host-based Rendering |
16 | |||
17 | 13 | Justin Sherrill | Only a single template of each type may be rendered for a system. Foreman determines which template to use following these rules: |
18 | 1 | Justin Sherrill | |
19 | 13 | Justin Sherrill | 1. Only the templates of the appropriate kind and associated with the hosts operating system are considered |
20 | 2. If a template has a hostgroup/environment combination that matches that of the host, use this template else |
||
21 | 3. If a template is associated with the environment of the host, use this template, else |
||
22 | 4. Use the first template found associated with the operating system associated with the host. |
||
23 | 1 | Justin Sherrill | |
24 | 13 | Justin Sherrill | So essentially, the hostgroup/environment combination is used first, then just the environment, and finally just the operating system of the host. |
25 | |||
26 | |||
27 | 1 | Justin Sherrill | To access a template of a certain type simply use this url: |
28 | |||
29 | 13 | Justin Sherrill | @/unattended/KIND_NAME@ |
30 | 1 | Justin Sherrill | |
31 | 13 | Justin Sherrill | For example: @/unattended/provision@ |
32 | 12 | Justin Sherrill | would render the provisioning template. The host will be based on the IP Address it is accessed from. To spoof a template simply access the url in this manner: |
33 | |||
34 | 13 | Justin Sherrill | @/unattended/provision?spoof=192.168.0.1@ |
35 | 12 | Justin Sherrill | |
36 | where 192.168.0.1 is the ip address of the system you want to spoof. This allows you to view a template for a particular system from anywhere. |
||
37 | 8 | Justin Sherrill | |
38 | |||
39 | h3. Hostgroup-based rendering |
||
40 | 9 | Justin Sherrill | |
41 | 8 | Justin Sherrill | Allows any template to be rendered for any Hostgroup. When rendering using a hostgroup, @host is actually the hostgroup instead of a defined host. The default values for the hostgroup are used for templated values. This means if a value is not set in the hostgroup, you may get an error when rendering the template. To access a template using a Hostgroup to render, simply use this URL: |
42 | |||
43 | /unattended/template/Template Name/Hostgroup Name |
||
44 | |||
45 | For example, a hostgroup of name Finance, and a template named WebServerKickstart could be rendered using the url: |
||
46 | |||
47 | 11 | Justin Sherrill | /unattended/template/WebServerKickstart/Finance |
48 | 1 | Justin Sherrill | |
49 | 10 | Justin Sherrill | h4. PXE Menus |
50 | |||
51 | 16 | Justin Sherrill | Pxe Menus can be deployed to smart proxies from the Config Templates list page (/config_templates). All provision templates will be added with each of their hostgroup combinations. For example if the template "WebServerKickstart" is associated to the Hostgroup1/Production, Hostgroup2/Production, and Hostgroup2/Testing combinations, the template would only be added twice. Once for WebServerKickstart-Hostgroup1 and WebServerKickstart-Hostgroup2. |
52 | 8 | Justin Sherrill | |
53 | h2. Writing templates |
||
54 | |||
55 | |||
56 | |||
57 | h2. Functions and macros: |
||
58 | |||
59 | 1 | Justin Sherrill | |_.Name|_.Description|_.Example| |
60 | |root_pass |The root password configured for the system| | |
||
61 | 7 | Justin Sherrill | |ks_console | | | |
62 | 6 | Justin Sherrill | |snippets(name) | Renders the specified snippet | | |
63 | 1 | Justin Sherrill | |foreman_url(kind)| Provides the full URL to a host-rendered template of the given kind | foreman_url("provision") => http://HOST/unattended/provision | |
64 | |@host |The name of the host| | |
||
65 | |@host.name |The name of the host| | |
||
66 | |@host.diskLayout |The disklayout of the host (could come from the operating system)| | |
||
67 | |@host.puppetmaster |The puppetmaster the host should use | | |
||
68 | |@host.architecture |The arch of the host (i.e. x86_64)| | |
||
69 | |@host.operatingsystem|The operating system name| | |
||
70 | |@host.operatingsystem.media_url ||| |
||
71 | |@host.operatingsystem.major |The major version of the OS|| |
||
72 | |@host.operatingsystem.minor |The minor version of the OS|| |
||
73 | |@host.operatingsystem.family |The OS Family (I.e. redhat, debian, etc.)|| |
||
74 | |@host.url_for_boot(:kernel) ||| |
||
75 | |@host.url_for_boot(:initrd) ||| |
||
76 | |||
77 | |||
78 | 2 | Justin Sherrill | |
79 | 8 | Justin Sherrill | h3. Kickstart only variables: |
80 | 1 | Justin Sherrill | |
81 | |_.Name|_.Description|_.Example| |
||
82 | |@dynamic ||| |
||
83 | |@osver ||| |
||
84 | |@arch ||| |
||
85 | |@mediapath ||| |
||
86 | |@epel ||| |
||
87 | |@yumrepo ||| |
||
88 | |@static ||| |
||
89 | |||
90 | 8 | Justin Sherrill | h3. Preseed attributes: |
91 | 6 | Justin Sherrill | |
92 | 1 | Justin Sherrill | |_.Name|_.Description|_.Example| |
93 | |@preseed_path ||| |
||
94 | |@preseed_server ||| |