How to execute/run puppet class

puppet

I am new to puppet. I want to know how to execute/run a simple puppet class. Below is the class I am trying to execute using

puppet apply classExample.pp

classExample.pp is the file in which class is written.
This code just compiles the class and nothing happens.
How to execute this class?

 # A class with no parameters
class exampleClass {

 #create a directory
  file {"create directory":
    path => '/root/rahil/puppet/puppetDemo/tmp',
    ensure => "directory",
  }

}

Best Answer

What you did is defining a class.
But you also need to declare it.

For the sake of the example, it could look like this:

# A class with no parameters
class example_class {

  #create a directory
  file {"create directory":
    path => '/root/rahil/puppet/puppetDemo/tmp',
    ensure => "directory",
  }

}

class { 'example_class': }

Please note that I changed the name to example_class as upper case letters should not be used in class names.
And also note that usually you don't define and declare classes in the same file.
How that is done is a bigger topic, see Modules fundamentals Documentation for a start.

Related Topic