Ask Your Question
0

How to use external file for template or inline_template function

asked 2017-01-23 07:25:49 -0500

xFlasH gravatar image

Hi all,

I have a puppet recipe who should download and extract an archive file which contain an ERB file. I would like to use this extracted resource as a base for a new file content resource. Do you think it is possible ?

An example of code may be :

class test_erb {

 $destdir="/tmp"

  archive::artifactory { "config.zip":
    archive_path => "$destdir",
    url                   => "$artifactory/config.zip",
    extract           => true,
    extract_path => "$destdir/extracted",
    creates => File["$destdir/config.xml.erb"],
    cleanup      => false,
  }

file { "$destdir/config.xml" :
    ensure  => 'file',
    # content => template("$destdir/config.xml.erb"),
    content => inline_template(file("$destdir/config.xml.erb")),
    require      => File["$destdir/config.xml.erb"],
  }

}

in this case, Puppet (puppet apply) complains about not founding the resource $destdir/config.xml.erb

How can I be sure that this file will be present at deployment time an not compile-time? Should I put a dependency between the two resource declarations ?

Thanks a lot for your answers!

edit retag flag offensive close merge delete

Comments

the archive::artifictary resource doesn't happen until the catalog is applied, but compiling the catalog requires that it can reference all the templates that are needed for compilation.

DarylW gravatar imageDarylW ( 2017-01-23 13:46:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-23 14:00:53 -0500

DarylW gravatar image

updated 2017-01-23 14:01:36 -0500

The way puppet works is roughly the following:

  1. Establish certs(server and agent),
  2. pluginsync (custom facts and libs from server)
  3. gather facts (on client)
  4. send facts output (from client)
  5. use facts, modules, and hiera to calculate catalog (on server)
  6. send compiled catalog (to client)
  7. generate 'should be' and 'actual' resource list (on client)
  8. make 'actual' into 'should' (using the native types)
  9. send report of catalog application (to server)

What you are trying to do is get information from step 8 and use it to generate the catalog in step 5. When you run 'masterless' in puppet apply mode, the same steps happen in the same order, it's just that your machine performs both the client and server roles.

What you COULD do is have the templates that you want to use a part of a module that is pulled into your environment (I'm not sure if you are using a control-repo with r10k or librarian-puppet, or what), and you would 'resolve' your module dependencies using puppet-librarian or r10k, and then run your puppet apply, that way you could bring down your 'artifact' module as a part of setting up your puppet environment prior to running puppet apply

edit flag offensive delete link more

Comments

Your proposition (embed the erb as a module resource) has already been tried. But we were trying to have something more "decoupled" of the puppet module. Thanks for this detailed answer!

xFlasH gravatar imagexFlasH ( 2017-01-24 01:58:15 -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

Stats

Asked: 2017-01-23 07:25:49 -0500

Seen: 145 times

Last updated: Jan 23