0

First off, I'm a ruby noob and I'm in a bit over my head, please be gentile.

I'm getting an exception on line 14 of this file, (written by someone else).

https://github.com/theforeman/kafo/blob/master/modules/kafo_configure/manifests/yaml_to_class.pp

  if is_hash($kafo_configure::params[$name]) {
    # The quotes around $classname seem to matter to puppet's parser...
    $params = { "${classname}" => $kafo_configure::params[$name] }
    create_resources( 'class', $params )

I need to adding a debugging to determine why the 'create_resources' function call is crashing.

exception object expected at /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems\
/kafo-0.6.0/modules/kafo_configure/manifests/yaml_to_class.pp:14 on node foo.bar

When I try and print out the value of $name, I encounter an error that 'puts' is an unknown function.

  if is_hash($kafo_configure::params[$name]) {
    puts "debugging name is #{name}"
    # The quotes around $classname seem to matter to puppet's parser...
    $params = { "${classname}" => $kafo_configure::params[$name] }
    create_resources( 'class', $params )

I've also tried the following syntaxes:

    puts "debugging name is #{name}"
    print "debugging name is #{name}"
    puts "debugging name is $name"
    print "debugging name is $name"
    puts "debugging name is #{$name}"

Can anyone explain:
1. Why this function is unable to print/put ?
2. Is there another way to show what the value of that $name variable is?

Update

As pointed out, I've also used this syntax puts "debugging name is #{$name}"

Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
spuder
  • 17,437
  • 19
  • 87
  • 153
  • I don't see it from that 4 lines. Add to them then, to avoid misunderstanding. – zishe May 29 '14 at 01:04
  • 4
    This is not Ruby — it looks like Perl. Er, correction, from looking at the file, it looks like it's Puppet's manifest language. At any rate, not Ruby. – Chuck May 29 '14 at 01:10
  • It's not Perl. It's the Puppet DSL. Ruby is a no go there. you can use something like `$foo = inline_template("<%= puts 'foo' %>")`. I don't remember what log file this would write to though. – ptierno Jun 01 '14 at 05:26
  • @Chuck: Sorry, just realized you noticed it was Puppet. My bad :) – ptierno Jun 01 '14 at 05:27

3 Answers3

2

You can use the notice function for printing debugging messages.

The fail function you've pointed out will print the message, but will also break the manifest execution.

Emyl
  • 10,460
  • 2
  • 35
  • 34
1

Figured it out. Since puppet is written in ruby, I mistakenly assumed that I could use ruby inside of the puppet file.

I was able to print out the debuging statement I needed using puppet's built in 'fail' function

fail("if the value of name is ${name}")

Working solution

if is_hash($kafo_configure::params[$name]) {
# The quotes around $classname seem to matter to puppet's parser...
fail("if the value of name is ${name}")
$params = { "${classname}" => $kafo_configure::params[$name] }
create_resources( 'class', $params )
spuder
  • 17,437
  • 19
  • 87
  • 153
  • `Since puppet is written in ruby, I mistakenly assumed that I could use ruby inside of the puppet file.` Normally, that would not be a mistake. – 7stud May 29 '14 at 02:20
1

To make debug messages visible on the agent side, you can employ the notify { } resource type.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30