Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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.

Thanks Mateusz, but it didn't work: Warning: Unrecognised escape sequence '\c' in file /etc/puppet/environments/production/blah../blah... – SuperVertrix Mar 25, 2015 at 19:45 I updated the answer, both of you were closing the quotations around cmd.exe /c before you added the copy to location (c:\temp). So it will likely work better if the command you are trying to pass will actually execute outside of Puppet. ;) – ferventcoder Mar 25, 2015 at 21:56

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",
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.