spuder
spuder

Reputation: 18457

Ruby can't 'put', gives error 'Unknown function puts'

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

Upvotes: 0

Views: 335

Answers (3)

Felix Frank
Felix Frank

Reputation: 8223

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

Upvotes: 1

Emyl
Emyl

Reputation: 10536

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.

Upvotes: 2

spuder
spuder

Reputation: 18457

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 )

Upvotes: 1

Related Questions