0

Is there a way to print the value of an attribute in a puppet module? For example, if you have a file resource:

file {'myfile':
      path => '/this/is/my/path',
      ensure => present,
      owner => 'someuser',
      group => 'somegroup'
}

can you print the value of the 'path' attribute? Perhaps using a notify?

notify {"the value of path is: " __________}
Alex Nelson
  • 103
  • 1

1 Answers1

1

Not if you pass your attributes as literal strings.

However, you can re-use the attribute if you assign it to a variable. Example:

$file_path = '/this/is/my/path'

file { 'myfile':
  path   => $file_path,
  ensure => present,
  owner  => 'someuser',
  group  => 'somegroup'
}

notify { "the value of path is: ${file_path}": }

Note the final colon that separates the resource name and the parameters (in this case there are none, so the resource is just terminated). The notify above could also be written as this (reference):

notify { 'my_notify':
  message =>  "the value of path is: ${file_path}",
}

Also, note the correct use of single and double quotes. According to Puppet Lint, double quotes should only be used when the string contains an interpolated variable, and such variables should be enclosed within curly braces.

Craig Watson
  • 9,575
  • 3
  • 32
  • 47
  • This is what I thought. I was hoping someone had some sort of 'magic' to be able to get it another way. Thanks! – Alex Nelson Aug 01 '13 at 16:16