Ubuntu – Using Foreman to install packages

foremanpuppetUbuntu

I have an Ubuntu 14.04 server running Foreman and Puppet (as the master), and some other Ubuntu 14.04 machines which are Puppet nodes. I want to use Foreman to make sure the Puppet nodes have certain packages installed. With regular Puppet, you can include something like

package { "screen":
    ensure => "installed"
}

which triggers an apt command and installs screen. But I'm not sure how to do this with Foreman. Is it even possible? I haven't found any references to it, and all of my search results have some up with how to install Foreman itself.

Best Answer

First, I don't use Foreman, I use hiera. The examples should give you an idea what an ENC is for, not provide a complete howto for using Foreman. Here's one that covers the basics.

Second, Puppetlabs provides a similar site to this one for puppet specific questions, so you might want to look there for help.

On to your question:

Foreman is, like hiera, an external node classifier (ENC). That means, that you can use it to attach classes to be loaded or variables to a node to be used by loaded classes.

What you still should (and have to) do, is to provide puppet with modules and manifests to load.

So an example would be writing a module named misc, put in /etc/puppet/environment/prod/modules/misc.

class misc {
    package { "screen":
        ensure => "installed"
    }
}

You can use Foreman to attach the class misc to sample nodes node01.example.com and node02.example.com to install screen on both nodes.

Another example using variables:

class misc(
  $packages = [ "screen" ],
) {
    package { $packages:
        ensure => "installed"
    }
}

You can use Foreman to attach the class misc to sample nodes node01.example.com and node02.example.com, and set the variable misc::packages to something like [ "vim", "screen", "telnet" ] to make it install vim, screen and telnet on both nodes.