Ask Your Question

How to put %userprofile% in puppet exec

asked 2018-06-18 03:12:42 -0500

rameltisqui gravatar image

I need to move a file form a temporary folder to a AppData folder, which is under the %userprofile% folder.

If I try this:

exec { 'copy' :
 command => 'C:\\Windows\System32\cmd.exe /c "copy C:\tmp\file.txt %userprofile%\AppData\Roaming\"',

It throws an error. If I put the full path in, it works:

exec { 'copy' :
 command => 'C:\\Windows\System32\cmd.exe /c "copy C:\tmp\file.txt C:\\Users\usertest\AppData\Roaming\"',

But not all the computers have the same Username.

Is there any way to do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-26 23:52:37 -0500

joshc gravatar image

You'll need to define a userprofile fact and then reference the fact in the command, e.g. command => "C:\\Windows\\System32\\cmd.exe ...$userprofile...". Since you need to interpolate the string, you'll need to use double quotes, not single quotes. And because of the double quotes, you'll need to escape each backslash, e.g. C:\\Windows\\System32\\cmd.exe.

You'll also need to use onlyif, unless, or creates to make your exec resource idempotent, otherwise puppet will try to apply the resource every time it runs, which is probably not what you want.

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


Asked: 2018-06-18 03:12:42 -0500

Seen: 76 times

Last updated: Jun 26