Ask Your Question

How to use a relative path for File on Windows?

asked 2014-02-11 06:55:03 -0500

oleksii gravatar image

Is it possible to use a relative path for the file in Windows? If not, can I use puppet to resolve absolute file path from the relative?

I need to check that an installation file exist (and then run it). Install file comes with the module and is located in the /modules/foo/files/foo_installer.exe. Here is a small snapshot of my module

class foo {                 
    file { 'installer':
      ensure    => 'file',
      path      => 'puppet:///modules/foo/files/foo_installer.exe'        

When I run this

puppet apply --modulepath="C:\scripts\windows\puppet\modules" 

I get ... (more)

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2014-02-20 11:38:24 -0500

joshc gravatar image

The file path must refer to an absolute path. However, you can use a custom fact (in your module) to define a base directory, and then refer to the fact in your manifest:

file { "$my_basedir/foo_installer.exe":
  ensure => file
  source => 'puppet:///modules/foo/files/foo_installer.exe',

Your custom fact can resolve my_basedir from the registry, from environment variables, etc. If it depends on a well-known folder id, you can use the win32-dir gem to look these up:

Facter.add(:my_basedir) do
  confine :kernel => :windows
  setcode do
    require 'win32/dir'
edit flag offensive delete link more


This is the correct answer with regards to relative file path. You don't use them.

rob gravatar imagerob ( 2014-10-03 23:11:35 -0500 )edit

answered 2014-02-14 16:10:25 -0500

fnaard gravatar image

If you're just trying to fetch the .exe from your master and put it somewhere, that's pretty simple, and the File resource is exactly what you want. The 'source' attribute is what you use to tell puppet where to fetch the original file from. The 'path' attribute is what you use to tell puppet where to save the downloaded file. For instance, in your example, to fetch the file from the module's files directory, and save it in c:\tmp, you'd do something like this:

class foo {
  file { 'installer':
    ensure => 'file',
    source => 'puppet:///modules/foo/foo_installer ...
edit flag offensive delete link more

answered 2014-02-12 02:15:11 -0500

Rob H gravatar image

I don't think what you are doing is correct. If your running a puppet apply locally on the windows system then using the URI puppet:// in your resource declaration is probably not going to work. This defaults to your master so I would have thought when running local puppet apply it wont work. If it's puppet apply you are actually running I would wrap puppet in a batch file, this way you can use FACTER variables to set your desired location then reference the variable from within your manifest. The variable can differ on systems but why you ... (more)

edit flag offensive delete link more


Actually, `puppet apply` will "pretend" to be the master when it runs into a puppet:/// URI. So, if you're using puppet:/// in a manifest, the apply will look in ...(more)

fnaard gravatar imagefnaard ( 2014-02-24 12:07:39 -0500 )edit

answered 2014-02-12 03:17:24 -0500

ttytrtr gravatar image

updated 2014-06-15 20:33:31 -0500


edit flag offensive delete link more


It's always nice to give credit to the original author when you copy&paste from other sources:

Stefan gravatar imageStefan ( 2014-02-20 13:13:38 -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



Asked: 2014-02-11 06:55:03 -0500

Seen: 1,216 times

Last updated: Jun 15 '14