Project

General

Profile

Instantiate Puppet resources » History » Version 1

Dominic Cleal, 09/24/2014 09:15 AM

1 1 Dominic Cleal
h1. Instantiate Puppet resources
2
3
Foreman acts as an external node classifier (ENC) for Puppet, which allows it to pass a list of classes, global and class parameters.  It isn't able to instantiate individual resources (such as a file or package), or a defined type through this interface.
4
5
Instead, you have a few possible approaches.
6
7
h2. Creating a simple class or module
8
9
Resources should generally be kept in a class which can then be included where needed.  For static resources, this is the best way.
10
11
* "Learning Puppet — Modules and Classes":https://docs.puppetlabs.com/learning/modules1.html
12
13
h2. Basic dynamic resources with arrays
14
15
If the resources you're managing are simple and all have the same properties and parameters, you can use Puppet's array resource declaration syntax ("array of title docs":https://docs.puppetlabs.com/puppet/3/reference/lang_resources.html#array-of-titles) to create many resources at once.
16
17
In this example to install a list of packages, we create /etc/puppet/environments/production/modules/packages/manifests/init.pp with:
18
19
<pre>
20
class packages($list = []) {
21
  package { $list:
22
    ensure => installed,
23
  }
24
}
25
</pre>
26
27
When you import this "packages" class, it will have a "list" parameter.  In Foreman's UI, go to _Configure_, _Puppet classes_, "packages", _Smart class parameters_ and tick the _Override_ checkbox on the "list" parameter.  Set the _Parameter type_ to _json_ and use "JSON syntax":http://www.w3schools.com/json/json_syntax.asp to set the list parameter to an array of values, e.g.
28
29
    ["httpd","vim"]
30
31
You can then override this per host or host group and supply a new array.