Search code examples
virtual-machinepuppet

Puppet Learning VM: Manifests and Classes (Ruby)


I am working ON Puppets Learning VM which uses Ruby which I am not too familiar with. I am stuck on Exercise 5. Manifests and classes, Task 2 https://kjhenner.gitbooks.io/puppet-quest-guide/content/quests/manifests_and_classes.html

In the previous Task I create cowsay.pp :

class cowsayings::cowsay {
  package { 'cowsay':
    ensure => present,
    provider => 'gem',
  }
}

Then in task two I am suppose to create the same file in another location with instructions:

Task 2:

If you were going to apply this code to your production infrastructure, you would use the console's node classifier to classify any nodes that needed cowsay installed with the cowsay with your cowsay class. As you're working on a module, however, it's useful to apply a class directly. By convention, these test manifests are kept in an examples directory. (You may also sometimes see these manifests in the tests directory.)

To actually declare the class, create a cowsay.pp test in the examples directory.

vim cowsayings/examples/cowsay.pp In this manifest, declare the cowsay class with the include keyword.

include cowsayings::cowsay

I am not sure how to create this second file and where to add this line. I have tried both:

class cowsayings::coway {
  include cowsayings::cowsay
  package { 'cowsay':
    ensure   => present,
    provider => 'gem',
  }
}

and

class cowsayings{
  include cowsayings::cowsay
}

Although it does not seem to be working and when I run it, it does not install cowsay correctly in Task 3 (in the link above that I posted


Solution

  • The manifest in the examples directory just needs that one line with "include cowsayings::cowsay".

    There are two tasks that have to happen with puppet, "defining" classes and "declaring" them. The cowsayings/manifests/cowsay.pp contains the definition, but you need to actually declare the class in order to make something happen.

    That's what puppet apply cowsayings/examples/cowsay.pp does, it declares the class.