About | FAQ | Help
Ask Your Question

How to access windows %TEMP% environment variable in puppet

asked 2017-10-04 15:48:24 -0500

peeyar gravatar image

I am trying to use the %TEMP% variable to copy a .sql file , so I can run it. But somehow the %TEMP% is not expanding while running puppet and the statement is failing..

file{'SQL Script File': source => 'puppet:///modules/custom/updatelog.sql', path => '%TEMP%\updatelog.sql', }

Can some one tell me how to access these windows environment variables in puppet...?

  • List item
edit retag flag offensive close merge delete


I don't know how to extract environment variables in MS (as facts), but variable interpolation goes like this: https://docs.puppet.com/puppet/latest/lang_variables.html#interpolation

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-07 08:27:59 -0500 )edit

Does your %TEMP% appear in the output of `facter(8)`? Then you're lucky. Otherwise you have to write a program extracting your environment variable https://docs.puppet.com/facter/latest/custom_facts.html

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-07 08:30:00 -0500 )edit

Doesn't the MS world know something like the “filesystem hierarchy standard” (hier(7))? I mean, couldn't you just specify a static string like `/tmp` you'd usually do in the Linux world?

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-07 08:32:55 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-10-10 10:30:23 -0500

joshc gravatar image

Unfortunately, puppet doesn't support windows environment variables in paths like that. You'll want to create a custom fact and then reference that fact in your manifest:

Facter.add(:temp) do
  setcode do

Then in your manifest:

path => "${temp}\\updatelog.sql"

In order to interpolate the temp fact value, you'll need to use double quotes, which means you have to escape the backslash.

See also https://tickets.puppetlabs.com/browse...

edit flag offensive delete link more

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-10-04 15:48:24 -0500

Seen: 314 times

Last updated: Oct 10 '17