Skip to content

Commit

Permalink
Parameters UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
orrabin committed Oct 12, 2015
1 parent 0bee440 commit 9d83424
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 42 deletions.
4 changes: 2 additions & 2 deletions _includes/manuals/1.1/4.2.5_param_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ This will be converted to the normal ["a","b"] syntax when you save. You can als

If Foreman manages the value of a class parameter ("override = true"), it's also possible to update a host-specific override from the host itself. That way you don't have to grant access to the Puppet Classes page to everyone. From a Host, click Edit, go 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:

![Host Edit](/static/images/screenshots/param_classes/hostedit.png)
![Host Edit](/static/images/screenshots/param_classes_110/hostedit.png)

If you go back and look at the Puppet class, you'll see Foreman has added a matcher for that host:

![Host Matcher](/static/images/screenshots/param_classes/hostmatch.png)
![Host Matcher](/static/images/screenshots/param_classes_110/hostmatch.png)

Currently this only works for Hosts, not Hostgroups. For more complex logic, like matching on facts, use the Puppet Class page

Expand Down
2 changes: 1 addition & 1 deletion _includes/manuals/1.10/4.2.3_puppet_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Host inherit their list of global parameters from the following locations, in or
* Host group-level parameters, under *Configure > Host groups > edit > Parameters*.
* Host parameters, under *Hosts > All hosts > edit > Parameters*.

The final (most specific) level of global parameters applies only to a single host. Edit a Host and switch to the *Parameters*, and you will see all of its inherited parameters from the previous levels. Note that they will all be marked as "Scope: Global" as this refers to the Puppet scope, not the Foreman scope. You can override any of these previously-defined parameters or define new ones here.
The final (most specific) level of global parameters applies only to a single host. Edit a Host and switch to the *Parameters* tab, and you will see all of its inherited parameters from the previous levels. You can override any of these previously-defined parameters or define new ones here.

#### Checking the results

Expand Down
16 changes: 11 additions & 5 deletions _includes/manuals/1.10/4.2.4_smart_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Smart variables are a tool to provide global parameters (key/value data), normal

Smart variables are associated with a Puppet class, but they result in a global parameter. They may have multiple possible values, all depending on hierarchical context or various conditions a user can wish to apply. For example:

![Example](/static/images/screenshots/4.2.4_smartvar.png)
![Example](/static/images/screenshots/param_classes_110/4.2.4_smartvar.png)

#### Creating a smart variable

Expand All @@ -16,9 +16,13 @@ Click New Variable, and you will be presented with a set of input fields:
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Name</td>
<td>Parameter</td>
<td>What the parameter will be called in the ENC data</td>
</tr>
<tr>
<td>Parameter type</td>
<td>This dropdown allows validating that all values are of the correct type</td>
</tr>
<tr>
<td>Description</td>
<td>A free form text box for your own information</td>
Expand All @@ -29,12 +33,12 @@ Click New Variable, and you will be presented with a set of input fields:
</tr>
</tbody></table>

Once you've created the defaults for your smart variable, you can then add at least one criterion to match against - click the "plus" under your variable, and two more input fields will appear:
Once you've created the defaults for your smart variable, you can then add at least one criterion to match against - click the "Add Matcher" button at the bottom of the form and a new row will be added to the matchers table:

<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>Should state a name = value relationship that Foreman use to match against the entries in searchlist</td>
</tr>
<tr>
Expand All @@ -43,6 +47,8 @@ Once you've created the defaults for your smart variable, you can then add at le
</tr>
</tbody></table>

![Example of a matcher on domain](/static/images/screenshots/param_classes_110/smart_variable_matcher_row.png)

#### Advanced usage

Smart variables are based on the smart matchers technology, and have a number of advanced features such as validation and multiple data types. More about these can be found in the [Smart Matchers](/manuals/{{page.version}}/index.html#4.2.6SmartMatchers) section.
Expand All @@ -51,6 +57,6 @@ Smart variables are based on the smart matchers technology, and have a number of

It's also possible to retrieve these values if you're not using a ENC, via a custom Puppet function or a http request.. You'll need to retrieve the value from

https://foreman/api/v2/hosts/<fqdn>/lookup_keys/<key>
https://foreman/api/v2/hosts/<fqdn>/smart_variables/<parameter>

You can find a ready-made function for your puppet module [here](https://github.com/theforeman/puppet-foreman/blob/master/lib/puppet/parser/functions/smartvar.rb)
26 changes: 18 additions & 8 deletions _includes/manuals/1.10/4.2.5_param_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ foreman-installer has several, you can download a few modules from the Puppet
Forge. Once you have some parameterized modules, import your classes (see
[**4.2.2 Classes**](manuals/{{page.version}}/index.html#4.2.2Classes))

![Import](/static/images/screenshots/param_classes/import.png)
![Import](/static/images/screenshots/param_classes_110/import.png)

#### Configure a class

Expand All @@ -23,36 +23,46 @@ This example will work with the *foreman* class from the installer. Click on the

The middle tab, "Smart Class Parameter", is the important one. Click onto that, and you should see something like this:

![Edit](/static/images/screenshots/param_classes/edit.png)
![Edit](/static/images/screenshots/param_classes_110/edit.png)

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.

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:

* Puppet Environments / Name
* Puppet Environments / Parameter
* These can't be edited, they're just for information.
* Description
* Purely information textbox for making notes in. Not passed to Puppet, or reused anywhere else
* Override (**important**)
* If this is unchecked, Foreman will not attempt to control this variable, and it will not be passed to Puppet via the ENC.
* Type
* Key type
* The type of data we want to pass. Most commonly a string, but many other data types are supported. There's no easy way to tell what type of data Puppet is expecting, so you will need to read through the code/documentation that comes with a particular module to find out. Changing the type field requires an appropriately set "Default Value" field.
* Default Value
* 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

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:

![User Param](/static/images/screenshots/param_classes/user-param.png)
![User Param](/static/images/screenshots/param_classes_110/user_param.png)

<div class="alert alert-info">Tip: you can set Override on all parameters on a class from the Puppet classes list, clicking the dropdown menu on the right and clicking "Override all parameters".</div>

#### Default value

Most importantly, the *Override* option has to be enabled for Foreman to control this variable, otherwise it will never be managed and will not appear in the ENC output.

The *Default value* will be supplied in the ENC output and should be a supported value, such as a string, YAML or JSON structure or use template features (see following sections). When the *Use Puppet default* checkbox is enabled, no default value will be present in the ENC output unless an override matches. Puppet will instead use the class default or data binding (Hiera) as usual.

The default will be imported from the Puppet manifest initially, but if the class uses an inherited params pattern, it may contain an unhelpful string such as `${$foreman::params::user}`. Foreman is unable to parse the actual value in this case as it might change when evaluated. Change the suggested default to the actual value, or tick the *Use Puppet default* checkbox.

![Use puppet default](/static/images/screenshots/param_classes_110/use_puppet_default.png)

#### Setting up matchers

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.

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:

![Matcher](/static/images/screenshots/param_classes/matcher.png)
![Matcher](/static/images/screenshots/param_classes_110/matcher.png)

This is a basic configuration - for more complex examples of using matchers,
see the [Smart Matchers](manuals/{{page.version}}/index.html#4.2.6SmartMatchers) section.
Expand All @@ -61,11 +71,11 @@ see the [Smart Matchers](manuals/{{page.version}}/index.html#4.2.6SmartMatchers)

If Foreman manages the value of a class parameter ("override = true"), it's also possible to update a host-specific override from the host itself. That way you don't have to grant access to the Puppet Classes page to everyone. From a Host, click Edit, go 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:

![Host Edit](/static/images/screenshots/param_classes/hostedit.png)
![Host Edit](/static/images/screenshots/param_classes_110/hostedit.png)

If you go back and look at the Puppet class, you'll see Foreman has added a matcher for that host:

![Host Matcher](/static/images/screenshots/param_classes/hostmatch.png)
![Host Matcher](/static/images/screenshots/param_classes_110/hostmatch.png)

The same override button is available on a host group's *Parameters* tab. For more complex logic, like matching on facts, use the Puppet Class page.

Expand Down
50 changes: 24 additions & 26 deletions _includes/manuals/1.10/4.2.6_matchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ The same smart matching technology underpins both smart variables and smart clas
1. Optional validation of values.
1. Template processing of values for dynamic content.

#### Default value

Most importantly, the *Override* option has to be enabled for Foreman to control this variable, otherwise it will never be managed and will not appear in the ENC output.

The *Default value* will be supplied in the ENC output and should be a supported value, such as a string, YAML or JSON structure or use template features (see following sections). When the *Use Puppet default* checkbox is enabled, no default value will be present in the ENC output unless an override matches. Puppet will instead use the class default or data binding (Hiera) as usual.

The default will be imported from the Puppet manifest initially, but if the class uses an inherited params pattern, it may contain an unhelpful string such as `${$foreman::params::user}`. Foreman is unable to parse the actual value in this case as it might change when evaluated. Change the suggested default to the actual value, or tick the *Use Puppet default* checkbox.

#### Ordering

Overrides are processed in the order of precedence set in the *Order* field, from most to least specific (first match wins, unless merging is enabled). This is a list of host attributes and fact names that overrides will be checked against. If no override from this list matches, the default value is used.
Expand All @@ -35,12 +27,12 @@ Note that there's a name conflict between the "operatingsystem" fact and Foreman

#### Overrides / matchers

Once defaults have been filled in for your parameter, you can then add criteria to match against - click the *Add Matcher-Value* button under your parameter, and more input fields will appear:
Once defaults have been filled in for your parameter, you can then add criteria to match against - click the *Add Matcher* button under your parameter, and more input fields will appear:

<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>Should state a name = value relationship that Foreman use to match against the entries in the order list</td>
</tr>
<tr>
Expand All @@ -49,13 +41,13 @@ Once defaults have been filled in for your parameter, you can then add criteria
</tr>
<tr>
<td>Use Puppet default</td>
<td>Instead of providing a value, this parameter will not be supplied in the ENC output (use to prevent a default value being returned)</td>
<td>Instead of providing a value, this parameter will not be supplied in the ENC output (use to prevent a default value being returned) - only for smart class parameters</td>
</tr>
</tbody></table>

As an example, 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 *Add Matcher-Value* button, and fill it out like this:

![Matcher](/static/images/screenshots/param_classes/matcher.png)
![Matcher](/static/images/screenshots/param_classes_110/matcher.png)

The match field currently supports string equality only, the values must match exactly.

Expand All @@ -65,6 +57,8 @@ When the data type is a hash or array, ticking *Merge overrides* will cause valu

Merging is "deep", so nested hashes and arrays will gain values rather than being overwritten entirely.

The *Merge default* option adds the default value as one of the values to merge, it will get the least important priority so one of the other values may overwrite it.

When the data type is an array, the *Avoid duplicates* option will de-duplicate the resulting array.

#### Data types
Expand All @@ -80,20 +74,24 @@ The type of data we want to pass to Puppet can be set in the *Parameter type* fi
* YAML - Any valid YAML input.
* JSON - Any valid JSON input.

There's no easy way to tell what type of data the Puppet manifest is expecting, so you will need to read through the code/documentation that comes with a particular module to find out. Changing the type field requires an appropriately set "Default Value" field.
There's no easy way to tell what type of data the Puppet manifest is expecting, so you will need to read through the code/documentation that comes with a particular module to find out. Changing the type field requires an appropriately set "Default Value" field.

##### Complex data

Here's an example of adding an array parameter. Note the use of YAML in the edit box:

![Array](/static/images/screenshots/param_classes/array.png)
![Array](/static/images/screenshots/param_classes_110/array.png)

This will be converted to the JSON `["a","b"]` syntax when you save. You can also use hashes in YAML or JSON as data types too.

Note that the JSON hash syntax is not the same as Puppet's hash syntax: `{"example":"value"}`

#### Input validation

The *Optional input validator* section can be used to restrict the allowed values for the parameter. 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.

The input validation section is hidden by default but can be opened by clicking on its title. When changing the parameter type this section will be automatically expanded to change the validations according to the new type.

<table class="table table-bordered table-condensed">
<tbody>
<tr>
Expand All @@ -106,13 +104,13 @@ Note that the JSON hash syntax is not the same as Puppet's hash syntax: `{"examp
</tr>
</tbody></table>

The *Optional input validator* section can be used to restrict the allowed values for the parameter. 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.

For example, to restrict the "user" field to either "foreman" or "foremandev", tick the Required checkbox, and then set:

* Type: List
* Rule: foreman,foremandev

![Validators](/static/images/screenshots/param_classes_110/validators.png)

##### String validators

At present, the string type cannot be validated - leave the validator field blank, and all strings in the variable will be considered acceptable
Expand All @@ -127,7 +125,7 @@ Because Foreman offers templating capabilities, you can utilise pre-existing var

Let's look a quick example situation: we need to configure RabbitMQ and have it use our existing Puppet SSL certs. Using what we've learnt above, we jump into the RabbitMQ class and configure the "ssl cert" parameter as such:

![Template Variable](/static/images/screenshots/param_classes/template-variable-rabbit-ssl-cert.png)
![Template Variable](/static/images/screenshots/param_classes_110/template-variable-rabbit-ssl-cert.png)

As you can see we're utilising a template variable within the parameter's string just like we would in a normal template file. The important part of this string, as we're sure you've gathered, is the "@host.name" element. This pulls the FQDN from Foreman's facts and inserts it into the string.

Expand All @@ -142,7 +140,7 @@ All our hosts use *server.foo* for something, except bob.domain.com which uses *
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Name</td>
<td>Parameter</td>
<td>target</td>
</tr>
<tr>
Expand All @@ -166,7 +164,7 @@ All our hosts use *server.foo* for something, except bob.domain.com which uses *
<td>fqdn<br /> hostgroup<br /> os<br /> domain</td>
</tr>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>fqdn = bob.domain.com</td>
</tr>
<tr>
Expand All @@ -182,7 +180,7 @@ Most hosts need to use a port of *80* but all machines with a fact *region* and
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Name</td>
<td>Parameter</td>
<td>port</td>
</tr>
<tr>
Expand All @@ -206,15 +204,15 @@ Most hosts need to use a port of *80* but all machines with a fact *region* and
<td>fqdn<br /> region<br /> hostgroup<br /> os<br /> domain</td>
</tr>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>region = europe</td>
</tr>
<tr>
<td>Value</td>
<td>8080</td>
</tr>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>fqdn = foo.domain</td>
</tr>
<tr>
Expand All @@ -230,7 +228,7 @@ It is also possible to mix conditions, e.g.
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td>Name</td>
<td>Parameter</td>
<td>port</td>
</tr>
<tr>
Expand All @@ -254,16 +252,16 @@ It is also possible to mix conditions, e.g.
<td>fqdn<br /> region, hostgroup, environment<br /> hostgroup<br /> environment<br /> domain</td>
</tr>
<tr>
<td>Match</td>
<td>Attribute type</td>
<td>fqdn = foo.domain</td>
</tr>
<tr>
<td>Value</td>
<td>67</td>
</tr>
<tr>
<td>Match</td>
<td>region = europe, hostgroup = "web servers", environment = production</td>
<td>Attribute type</td>
<td>region, hostgroup, environment = europe, "web servers", production</td>
</tr>
<tr>
<td>Value</td>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9d83424

Please sign in to comment.