How to configure relative paths for puppet

pathspuppet

I've tried to google this, but haven't had any luck. My goal is to have a packaged directory with a puppet file and an accompanying directory holding file resources where I can just type puppet apply setup.pp and then puppet will do its thing.

I know that puppet's recommended workflow is to create modules and place the file resources there for copying. This is too inconvenient for me, as I don't want to have to install my modules there; I just want to be able to carry around this small package (i.e. pp file and file resources).

How can I configure my pp file to look into my sibling directory if I don't want to use absolute paths? Are there other environment variables I can manipulate to force puppet to look "in the right place"?

I saw a suggestion here that looks like it's extending Facter, but I'm just looking for something to put at the top of my pp file like this:

$basepath = exec{"/usr/bin/pwd":}

file {"/home/$title/.nanorc": source => "${basepath}/resources/.nanorc"}

Best Answer

Puppet is just Ruby under the hood. I would try to use the inline_template function:

file{"/home/$title/.nanorc":
  content => inline_template("<%= File.read(ENV["PWD"] + '/resources/.nanorc') %>"),
}