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

1 Answer 1

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.

1
  • This is what I thought. I was hoping someone had some sort of 'magic' to be able to get it another way. Thanks! Commented Aug 1, 2013 at 16:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.