Reputation: 81
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.
Upvotes: 3
Views: 4532
Reputation: 81
After spending too much time on getting this to work, I found a workaround like this:
$setup_msi = "i:\\data\\myprogram.msi"
exec { 'copy_MSI_c:\temp':
command => "C:\\windows\\system32\\cmd.exe /c copy ${setup_msi} c:\\temp",
}
Fr3edom21.
Upvotes: 0
Reputation: 392
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.
Upvotes: 2