Project

General

Profile

Parameterized class support » History » Version 2

Greg Sutcliffe, 11/26/2012 07:21 AM

1 1 Greg Sutcliffe
h1. Parameterized class support in Foreman
2
3
{{toc}}
4
5
The latest version of Foreman brings parameterized class support to the UI. This document is a walkthrough of setting up the required steps.
6
7
h2. Requirements
8
9
* Foreman 1.1+
10
* Foreman-Proxy 1.1+
11
* Puppet 2.6.5+
12
13
h2. Setup
14
15
Firstly, you'll need to enable the PCS support. Go to More->Settings, select the Puppet tab, and ensure Parametrized\_Classes\_in\_ENC" is set to True. 
16
17
(screenshot)
18
19 2 Greg Sutcliffe
Now you'll need to import some parameterized classes from your puppet master. You can skip this if you already have parameterized modules on your master, but since the [[Using_Puppet_Module_ready_to_use|foreman-installer]] has several such classes, we'll use those for this example. Assuming default paths (adjust this as necessary):
20 1 Greg Sutcliffe
21
    cd /etc/puppet/modules/production
22
git clone --recursive https://github.com/theforeman/foreman-installer -b develop
23
24
Now import your classes via the Foreman Proxy. Go to More-> Puppet Classes and click Import. If all goes well you'll get a screen showing the classes that are to be imported. Accept the changes, and you should return to the Puppet Classes page, with all the new classes listed.
25
26
(screenshot)
27
28
h2. Configure a class
29
30
We'll work with the "foreman" class from the installer. Click on the foreman class, and you should get a page with 3 tabs, like so:
31
32
(screenshot)
33
34
The midddle tab, "Smart Class Parameter", is the important one. Click onto that, and you should see something like this:
35
36
(screenshot)
37
38
On the left we have a list of possible parameters that the class supports. On the right, we have the configuration options for the parameter selected.
39
40
Lets configure the foreman class to change the user the foreman processes run as. Select the "user" parameter, at the end of the list. Now lets go through the options:
41
42
* Puppet Environments / Name
43
  These can't be edited, they're just for information.
44
* Description
45
  Purely information textbox for making notes in. Not passed to puppet, or reused anywhere else
46
* Override (*important*)
47
  If this is unchecked, Foreman will not attempt to control this variable, and it will not be passed to Puppet via the ENC.
48
* Type
49
  The type of data we want to pass. Most commonly a string, but many other data types are supported
50
* Default Value
51
  This will be imported from puppet initially, but if puppet is using any class inheritance, you'll get something unhelpful like "${$foreman::params::user}". This is because Foreman won't follow the inheritance, so you'll need to set a sensible default value
52
53
Ok, so let's configure our "user" parameter. We want to tick Override, set type to "String" and set the default value to "foreman", like so:
54
55
(screenshot)
56
57
h2. Setting up Matchers
58
59
We've configured the default, but that's not very useful. We need to be able to override the default for hosts or groups of hosts. To do that we need the "Override Value For Specific Hosts" section at the bottom of the page.
60
61
Let's say that any machine in the "development" puppet environment should use a value of "foremandev" instead of "foreman" for the "user" parameter. Add "environment" to the end of the matchers list, then click the "New Matcher-Value" button, and fill it out like this:
62
63
    Match: environment = development
64
Value: foremandev
65
66
(screenshot)
67
68
This is a basic configuration - for more complex examples of using matchers, see the SmartVariables page.
69
70
h2. Complex Data
71
72
Here's a screenshot of adding an array parameter. Note the use of YAML in the editbox:
73
74
(screenshot)
75
76
h2. Editing Param from within a Host
77
78
It's also possible to update a host-specific override from the host itself. So you don't have to grant access to the Puppet Classes page to everyone. From a Host, click Edit, got to the Parameters tab, and you'll see the variable, the class-scope, and the current value. You can then override the value for that host:
79
80
(screenshot)
81
82
If you go back and look at the Puppet class, you'll see Foreman has added a matcher for that host:
83
84
(screenshot)
85
86
Currently this only works for Hosts, not Hostgroups. For more complex logic, like matching on facts, use the Puppet Class page
87
88
h2. Input Validation
89
90
The "Optional Input Validation" section can be used to restrict the allowed values for the parameter. This functions in the same way as for SmartVariables, but it is important to note that the validation applies to changes made from the Host edit page as well as the Puppet Classes edit page. 
91
92
For example, to restrict the "user" field to either "foreman" or "foremandev", tick the Required checkbox, and then set:
93
94
    Type: List
95
Rule: foreman,foremandev