0
class mymodule::scripts::os_check {
  case $operatingsystem  {
    /(?i-mx:centos)/: { notify("You are using CentOS")}
    /(?i-mx:.*)/: { notify("You are using non-CentOS OS") }
  }
}

Why does this run without error, but not display either notify (on a server where the operatingsystem fact == CentOS)?

I am running this as a standalone script using puppet apply os-check.pp and just see the catalog run notify.

2 Answers 2

1

In addition to Craig's excellent answer, you need to:

include mymodule::scripts::os_check

Edit: Otherwise, you are just defining a class, not instantiating it.

4
  • Can you show sample code please?
    – user160910
    Oct 17, 2013 at 18:40
  • Thanks for the hat-tip - this is more likely a "correct" answer on reflection, the lack of output is a symptom of not including/instantiating a class. Oct 17, 2013 at 18:56
  • @Gregg - combine the include from my post with the code from Craig's post into one file: class mymodule::scripts::os_check { case $::operatingsystem { 'CentOS': { notify {'You are using CentOS': } } default: { notify {'You are using non-CentOS OS': } } } } include mymodule::scripts::os_check
    – jdkindy
    Oct 18, 2013 at 0:37
  • This was the correct answer. I was confused about class instantiate vs define. Thank you.
    – user160910
    Oct 22, 2013 at 17:24
5

Try this:

class mymodule::scripts::os_check {
  case $::operatingsystem  {

    'CentOS': {
      notify {'You are using CentOS': }
    }

    default: {
      notify {'You are using non-CentOS OS': }
    }
  }
}

A few points, in no particular order, with references in parentheses where appropriate:

  • You should be using single quotes for all strings that do not contain variable interpolation (Puppet Lint).
  • It's always better to match actual values when you know them - is there any specific reason why you're trying to match on a regex?
  • The operatingsystem fact should be matched by using the top-level namespace variable $::operatingsystem (Puppet Lint)
  • You should always provide a default option for any case statement (Puppet Lint)
  • Your notify syntax is wrong, you should instantiate a notify resource rather than trying to call it as a function (Puppet Type Reference)
3
  • That also gives me the same result notice: Finished catalog run in 0.01 seconds I do appreciate all of the insight, you have some good points.
    – user160910
    Sep 19, 2013 at 20:20
  • PS, I am also a bassplayer.
    – user160910
    Sep 19, 2013 at 20:24
  • Can you edit your original post with a pastebin/gist of the output of puppet agent --test --debug? Sep 19, 2013 at 20:43

You must log in to answer this question.