Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spuder/588dc4f38e92a762cd77 to your computer and use it in GitHub Desktop.
Save spuder/588dc4f38e92a762cd77 to your computer and use it in GitHub Desktop.
foreman defined types

How do you created defined types in the foreman? e.g. nrpe::command, apahce::vhost ect.. Based on these links, and from what users in the foreman irc chanel have suggested. https://github.com/theforeman/foreman-infra/blob/master/puppet/modules/users/manifests/init.pp https://groups.google.com/forum/#!topic/foreman-users/o-Sqjo-n21A

profile::nagios::client.pp

class profiles::nagios::client ( $checks ){
include nrpe
  if $checks {
    create_resources(nrpe::command, $checks)
  }
  else {
    fail('profiles::nagios::client recieved no parameter for $checks. Please create a resource hash in the foreman or hiera. see profiles::nagios::client.pp for more info')
  }

}

profile::tests::nagios::client.pp

$nrpe_hash = {
  'check-users' => {
    ensure  => present,
    command => 'check_users -w 5 -c 10',
  },
}

class {'profiles::nagios::client': checks => $nrpe_hash}

Here is how I am calling the class

puppet apply /vagrant/profile/tests/nagios/client.pp --debug --verbose

This throws the following error:

Error: can't convert nil into Hash at /usr/share/puppet/modules/profiles/manifests/nagios/client.pp:8 on node xxxxx
Wrapped exception:

Update

When trying to add the contents of tests/nagios/client.pp to the web interface of the forman, it throws an error

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: create_resources(): second argument must be a hash at /etc/puppet/environments/development/modules/profiles/manifests/nagios/client.pp:8 on node nagiosfun.vapor2.ac

I've tried

{{'check_users' => {ensure  => present,
    command => 'check_users -w 5 -c 10',
  },
  'check_load' => {
    ensure => present,
    command => 'check_load -w 15,10,5 -c 30,25,20',
  },
  'check_sda1' => {
    ensure => present,
    command => 'check_disk -w 20% -c 5% -p /dev/sda1',
  }}
"{'check_users' => {ensure  => present,
    command => 'check_users -w 5 -c 10',
  },
  'check_load' => {
    ensure => present,
    command => 'check_load -w 15,10,5 -c 30,25,20',
  },
  'check_sda1' => {
    ensure => present,
    command => 'check_disk -w 20% -c 5% -p /dev/sda1',
  }"
@spuder
Copy link
Author

spuder commented Nov 17, 2014

Instead of using a hash, use yaml, here is an example.

http://pastebin.com/DE2p97xC

You can verify that it is correct by going into the host in foreman, then clicking on the yaml button. it should look similar to the pastebin above!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment