External Nodes » History » Revision 27

« Previous | Revision 27/30 (diff) | Next »
Greg Sutcliffe, 10/04/2012 02:01 PM

Foreman can act as a classifier to Puppet through the external nodes interface.

You can now configure your hosts via a web interface, avoiding typing host specific information in your manifest.

Import your environment and classes setup

First of all, you probably want to let Foreman know about your setup, if you are using puppet modules - Foreman can import your setup automatically (environments and classes) by either:

Importing via the WebUI

Simply goto either Environments or Classes page (under more) and click import.
Note that you would need a proxy server installed on at least one puppet master for this functionality.

Importing via the CLI

rake puppet:import:puppet_classes RAILS_ENV=production

If you get a prompt you might avoid it with the batch mode using:

rake puppet:import:puppet_classes[batch] RAILS_ENV=production

If you prefer, you may manually add classes through the setting page, however, the class names must match Puppet classes.

if for some reason you can't see your nodes, please make sure that you have the following line in your puppet.conf file (or similar)


Define classes and variables per host

You can define per host, classes and variables(parameters), simply create/edit a host, and select its classes.
if you see an empty list, make sure that you do have classes (as define in the step above).

If you want to add variables(parameters), simply add them in the same page as a set name and value.

Host Groups

Foreman allows you to group classes, into common groups similar to node inheritances in puppet
Each group can contain many classes, variables, Provisioning information, and can even inherit from one another (You may think of them as templates for your hosts).

If you wish to override the parameters for a specific host, create a parameter with the same name in the host level,
Foreman will override the values defined in the group level.

Other places you can define parameters

It is also possible to define default (common) parameters for all of your hosts (setting -> Global parameters).
Additionally, you can also define them on the domain and operating system level (settings -> Domain -> Domain Parameters)

*The order in which the parameters are processed is:
Global, Domain, OS, Host Group and Node, the last occurrence of the parameter will be the one used. *

Example puppet external nodes script

You may find an example script under extras/puppet/foreman/templates/external_node.rb.erb - this is now outdated and should not be used

The new ENC script example is here: - edit it and copy it to, for example: /etc/puppet/node.rb.

You will need to edit the four variables at the top of the template:

  :url          => "<%25= @foreman_url %25>",
  :puppetdir    => "<%25= @puppet_home %25>",
  :facts        => <%25= @facts %25>,
  :storeconfigs => <%25= @storeconfigs %25>,
These are:
  • :url [string] - the full URL of your foreman server, eg 'http://myforeman.domain:3000'
  • :puppetdir [string] - where the vardir of your puppet installation is - usually '/var/lib/puppet'
  • :facts [boolean] - do you want to upload facts from the clients to Foreman? If so, make this true, if not false
  • :storeconfigs [boolean] - if you are sharing puppet's storeconfig database with Foreman, make this true, otherwise false

so a completed block might look like:

  :url          => "",
  :puppetdir    => "/var/lib/puppet",
  :facts        => true,
  :storeconfigs => false,

You would need to setup puppet to use external nodes

  external_nodes = /etc/puppet/node.rb
  node_terminus  = exec

Make sure that the puppet user can execute your enc script and it works:

sudo su - puppet -s /bin/bash
/etc/puppet/node.rb [the name of a node, eg agent.local]

should output something like:

    puppetmaster: puppet
    foreman_env: &id001 production
    root_pw: xybxa6JUkz63w
    - helloworld
  environment: *id001

For additional info please see Puppet documentation

Verify your setup

You may also click on the YAML link to see the output that would be used for puppet external nodes.

Import your external node setup from an older external node setup

If you already had an external node setup, you can import your old setup directly to Foreman

Note: This will import your classes and variables (parameters or tags) directly, that means that if you have any logic to dynamically generate the variables, it would not be imported.
However, if you define your parameters in the domain level (for example) they will not be added to every single host, therefor, if you want to apply certain parameters per domain, host class etc, you should define them prior to running the importer.

additionally, it will not import any invalid settings, e.g. parameters which has the same name as facts, or a non string parameters (some classifiers tend to create those).

To import the classes and parameters per host, run:

rake puppet:import:external_nodes script=/path/to/old_external_node_script RAILS_ENV=production

Note: This will only scan for hosts that already exists in our database, if you want to import hosts, use one of the other importers.

Updated by Greg Sutcliffe over 11 years ago · 27 revisions