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}"

4
  • I don't see it from that 4 lines. Add to them then, to avoid misunderstanding. Commented May 29, 2014 at 1: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. Commented May 29, 2014 at 1: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. Commented Jun 1, 2014 at 5:26
  • @Chuck: Sorry, just realized you noticed it was Puppet. My bad :) Commented Jun 1, 2014 at 5:27

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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 ) 

1 Comment

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.
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.