using variables in puppet exec

976 views
Skip to first unread message

Harish Kothuri

unread,
May 16, 2016, 7:09:01 AM5/16/16
to Puppet Users
Hi,

I'm trying to use puppet variables in exec command as follows

$pypredest = 'C:\PuppetSWT\Mysoftware.msi'
  
exec{ 'cmd /c copy /Y "\\shareloc\folder1\folder2\Mysoftware.msi" "${pypredest}"':
  
    path => $::path,
    creates => $pypredest,
    logoutput => true,
  }


Output from agent:
It says EXEC [ 'cmd /c copy /Y "\\shareloc\folder1\folder2\Mysoftware.msi" "${pypredest}"'] executed succesfully. But i don't the see the file copied to C:\PuppetSWT\ folder.


I get the file copied when i don't use variable.

$pypredest = 'C:\PuppetSWT\Mysoftware.msi'
  
exec{ 'cmd /c copy /Y "\\shareloc\folder1\folder2\Mysoftware.msi" "C:\PuppetSWT\Mysoftware.msi" ':
  
    path => $::path,
    creates => $pypredest,
    logoutput => true,
  }


-Thanks

Craig Dunn

unread,
May 16, 2016, 7:29:59 AM5/16/16
to puppet...@googlegroups.com

On Mon, May 16, 2016 at 1:09 PM, Harish Kothuri <harish...@gmail.com> wrote:

exec{ 'cmd /c copy /Y "\\shareloc\folder1\folder2\Mysoftware.msi" "${pypredest}"':


Your resource title is enclosed in single quotes which means everything will be taken literally and your variable will not be interpolated....

Something like this would fix that problem...

exec{ "cmd /c copy /Y \"\\shareloc\folder1\folder2\Mysoftware.msi\" \"${pypredest}\"":

Although I'm not sure why you need an exec to do this (disclaimer: I haven't used windows in years)

Can you not do this with the file resource?

file { $pypredest:
  ensure => file,
  source => '\\shareloc\folder1\folder2\Mysoftware.msi',
}


Regards
Craig

Harish Kothuri

unread,
May 16, 2016, 9:05:17 AM5/16/16
to Puppet Users
Thanks Craig,

It works fine now. 

The reason am not using "file" is , it is taking more time to copy file from share than executing the simple command.

Thanks,
Harish

Craig Dunn

unread,
May 16, 2016, 9:07:47 AM5/16/16
to puppet...@googlegroups.com
On Mon, May 16, 2016 at 3:05 PM, Harish Kothuri <harish...@gmail.com> wrote:
Thanks Craig,

It works fine now. 

Cool.
 

The reason am not using "file" is , it is taking more time to copy file from share than executing the simple command.


If you can quantify that with some test results it may be worth raising a ticket regarding that, maybe there are some improvements that could be made to the windows file provider.

 
Reply all
Reply to author
Forward
0 new messages