3

I just started using puppet. I don't know how to execute classes in puppet. I've my files "config.pp init.pp install.pp service.pp". For example install.pp :

class sshd::install{ ... }

Next, i declare my class in init.pp with "include sshd::install".

I also tried to run classes with :

class{'sshd::install':} -> class{'sshd::config':} ~> class{'sshd::service':}

After that, i launch "puppet apply init.pp" but nothing.

My scripts work individualy, but with classes i don't know how to execute all my classes.

Thanks

NPTK
  • 31
  • 1
  • 3

1 Answers1

4

I'm not sure how much research you've done into Puppet and how its code is structured, but these may help:

It appears that you are starting out with a basic module structure (based on your use of init/install/service), which is good, however your execution approach is that of a direct manifest (Not the module itself) which won't work within the module you are testing due to autoloading unless your files are inside a valid module path.

Basically: You want to put your class/module structured code within Puppet's module path (puppet config print modulepath) then you want to use another manifest file (.pp) to include your class.

An example file structure:

/etc/puppetlabs/code/modules/sshd/manifests/init.pp
                                            install.pp
                                            service.pp
/tmp/my_manifest.pp

Your class sshd(){ ... } code goes in the init.pp, and class sshd::install(){ ... } goes in install.pp etc...

Then the 'my_manifest.pp' would look something like this:

include ::sshd

And you would apply with: puppet apply /tmp/my_manifest.pp. Once this works, you can learn about the various approaches to applying manifests to your nodes (direct, like this, using an ENC, using a site.pp, etc... Feel free to do further reading).

Alternatively, as long as the module is within your modulepath (as mentioned above) you could simply do puppet apply -e 'include ::sshd'

In order to get the code that you have to operate the way you are expecting it to, it would need to look like this:

# Note: This is BAD code, do not reproduce/use
class sshd() {
  class{'sshd::install':} -> 
  class{'sshd::config':} ~> 
  class{'sshd::service':}
}
include sshd

or something similar, which entirely breaks how the module structure works. (In fact, that code will not work without the module in the correct path and will display some VERY odd behavior if executed directly. Do not write code like that.)

Josh Souza
  • 396
  • 1
  • 6