Ask Your Question

Include a puppet-served file (not a subtemplate) in a template

asked 2017-08-28 10:10:34 -0500

erichymowitz gravatar image

Greetings. I've tried searching, but I'm probably searching for the wrong words.

I have a module

class foo
  file { "/etc/foo.txt" :
    ensure => file,
    source => 'puppet:///modules/foo/foo.txt',

And a file ..../modules/foo/files/foo.txt with some text contained in it. Just text, nothing special.

I have a second module

class createfoo
  file { "/etc/" :
    ensure => file,
    content => template("bar/")

and I have a template ..../modules/createfoo/templates/ that looks something like this:

# this file was generated by puppet for <%= @hostname %>
# to create the foo.txt file
rm /etc/foo.txt
cat > /etc/foo.txt << EOF
chmod 644 /etc/foo.txt

Please don't ask why I need both; just accept that I need both.

The question is ... I have the word "um" in my template. What can I put there that says "go get me the file from puppet:///modules/foo/foo.txt and put it here" ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-08-28 18:38:13 -0500

You're looking for the file function and how to use it inside a template.

In short: replace “um” with:

<%= scope.function_file(['foo/foo.txt']) %>


<%= scope.call_function('file', ['foo/foo.txt']) %>
edit flag offensive delete link more


Thank you!!!

erichymowitz gravatar imageerichymowitz ( 2017-08-29 07:24:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-08-28 10:10:34 -0500

Seen: 17 times

Last updated: Aug 28