Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows puppet exec command file path

Tags:

windows

puppet

I wonder if it's possible in puppet (windows agent) for a variable to hold the value of a file name, then add this variable value to an exec windows cmd.exe command? i.e. I'm trying to copy a file from a shared drive to c:\temp like this:

$setup_msi = "myprogram.msi"

exec { 'copy_MSI_c:\temp': 
command => 'C:\\windows\system32\cmd.exe /c "copy i:\\data\\${setup_msi}" c:\\temp'
}

But when the windows puppet agent runs, puppet parses the $setup_msi variable name itself and not the value that said variable contains. I was hoping it would parse it like this: C:\windows\system32\cmd.exe /c "copy i:\data\myprogram.msi c:\temp"

Any help would be greattly appreciated.

Thanks.

Fr3edom21.

like image 641
SuperVertrix Avatar asked Jan 02 '26 04:01

SuperVertrix


1 Answers

The command string is containted within single quote marks and this is why the variable is not substitiuted.

Your code should be

$setup_msi = "myprogram.msi"

exec { 'copy_MSI_c:\temp': 
    command => "C:\\windows\system32\cmd.exe /c \"copy i:\\data\\${setup_msi} c:\\temp\""
}

Since usage of double quotation marks means that the string itself is going to be parsed by puppet, it is also necessary to escape any double quotes within that string, thus \"copy instead of "copy.

Hope this helps.

like image 58
Mateusz M. Avatar answered Jan 04 '26 12:01

Mateusz M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!