Puppet Windows exec

2,702 views
Skip to first unread message

Jay Ze

unread,
Mar 23, 2012, 5:32:27 AM3/23/12
to Puppet Users
Hi,

Is it correct that it's not possible to excecute Windows Commands
directly with the puppet run?

For example:

exec { 'ExecCreatedFolder':
command => "mkdir C:\PuppetOrdner\ExecCreatedFolder",
}




I allways have to bind it with a .bat file right?




file { 'c:/PuppetFolder/puppettest.bat':
ensure => file,
owner => 'administrator',
content => "mkdir C:\PuppetFolder\BatchCreatedFolder",
}


exec { 'c:/PuppetFolder/puppettest.bat':
require => File['c:/PuppetFolder/puppettest.bat'],
}

Paul Tötterman

unread,
Mar 23, 2012, 7:16:32 AM3/23/12
to puppet...@googlegroups.com
Hi Jay,
 
exec { 'ExecCreatedFolder':
       command => "mkdir C:\PuppetOrdner\​ExecCreatedFolder",
}

mkdir is a command implemented by the windows command processor cmd.exe, not a callable program. http://docs.puppetlabs.com/references/stable/type.html#exec states that the Windows provider can only call executables instead of giving commands to a shell.

That said, have you tried something like 'command => "cmd /c mkdir c:\test"' ?

Also, I hope you bring up mkdir purely for the sake of discussion, since file { 'C:/test': ensure => directory } works for creating directories.

Cheers,
Paul

Jay Ze

unread,
Mar 23, 2012, 7:33:44 AM3/23/12
to Puppet Users
On 23 Mrz., 12:16, Paul Tötterman <paul.totter...@gmail.com> wrote:
> Hi Jay,
>
> > exec { 'ExecCreatedFolder':
> >        command => "mkdir C:\PuppetOrdner\​ExecCreatedFolder",
> > }
>
> mkdir is a command implemented by the windows command processor cmd.exe,
> not a callable program.http://docs.puppetlabs.com/references/stable/type.html#execstates that the
> Windows provider can only call executables instead of giving commands to a
> shell.
>
> That said, have you tried something like 'command => "cmd /c mkdir
> c:\test"' ?
I tried it and it didn't work.. but I know what you mean.

It's OK

>
> Also, I hope you bring up mkdir purely for the sake of discussion, since
> file { 'C:/test': ensure => directory } works for creating directories.
Yes, It was just an example :-)
Just to try the ressource exec
>
> Cheers,
> Paul

Thx for your quick answer.

Josh Cooper

unread,
Mar 23, 2012, 11:41:22 AM3/23/12
to puppet...@googlegroups.com
On Fri, Mar 23, 2012 at 4:33 AM, Jay Ze <iltisann...@googlemail.com> wrote:
On 23 Mrz., 12:16, Paul Tötterman <paul.totter...@gmail.com> wrote:
> Hi Jay,
>
> > exec { 'ExecCreatedFolder':
> >        command => "mkdir C:\PuppetOrdner\​ExecCreatedFolder",
> > }
>
> mkdir is a command implemented by the windows command processor cmd.exe,
> not a callable program.http://docs.puppetlabs.com/references/stable/type.html#execstates that the
> Windows provider can only call executables instead of giving commands to a
> shell.
>
> That said, have you tried something like 'command => "cmd /c mkdir
> c:\test"' ?
I tried it and it didn't work.. but I know what you mean.

It's OK

The exec resource requires that command be an absolute path or that you specify the path parameter to resolve the executable. Since %windir% can vary across Windows agents, the easiest thing is to do use the agent's path fact:

exec { 'cmd /c echo hello':
  path => $::path,
  logoutput => true
}

Also note that I didn't specify a '.exe' extension. Puppet uses both the %PATH% and %PATHEXT% environment variables to resolve the executable. Or course, you can specify the extension if you want, e.g. cmd.exe /c echo hello.

>
> Also, I hope you bring up mkdir purely for the sake of discussion, since
> file { 'C:/test': ensure => directory } works for creating directories.
Yes, It was just an example :-)
Just to try the ressource exec
>
> Cheers,
> Paul

Thx for your quick answer.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--
Josh Cooper
Developer, Puppet Labs

Reply all
Reply to author
Forward
0 new messages