How do I "cd" (change directory) with Puppet's exec?

6,461 views
Skip to first unread message

Benjamin Lei

unread,
Jul 6, 2012, 1:31:38 AM7/6/12
to puppet...@googlegroups.com
I sort of "need" to do this to run a Makefile that uses local directories...

Benjamin Lei

unread,
Jul 6, 2012, 1:33:00 AM7/6/12
to puppet...@googlegroups.com
Specifically, when I have "cd" in command => ".." it says it cannot find the command "cd".

Hendrik Jäger

unread,
Jul 6, 2012, 3:10:13 AM7/6/12
to puppet...@googlegroups.com
Hi,

On Thu, 5 Jul 2012 22:33:00 -0700 (PDT)
Benjamin Lei <benle...@gmail.com> wrote:

> Specifically, when I have "cd" in command => ".." it says it cannot
> find the command "cd".

Because it is a builtin command in the shell. Either let a shell
execute your command or use the pwd (or cwd?) parameter.

Best regards

Hendrik Jäger
signature.asc

jcbollinger

unread,
Jul 6, 2012, 11:44:51 AM7/6/12
to puppet...@googlegroups.com


On Friday, July 6, 2012 2:10:13 AM UTC-5, Hendrik Jäger wrote:
[...] let a shell
execute your command [...]

Which you can do fairly easily by adding "provider => 'sh'" to your Exec's parameters.

Or if you need a non-default shell or you just like doing things the hard way, then you can use a variation on

bash -c 'my command here'

as your command.


John

Stefan Schulte

unread,
Jul 7, 2012, 11:09:29 AM7/7/12
to puppet...@googlegroups.com
On Fri, Jul 06, 2012 at 08:44:51AM -0700, jcbollinger wrote:
>
>
> On Friday, July 6, 2012 2:10:13 AM UTC-5, Hendrik J�ger wrote:
> >
> > [...] let a shell
> > execute your command [...]
> >
>
> Which you can do fairly easily by adding "provider => 'sh'" to your Exec's
> parameters.
>
> Or if you need a non-default shell or you just like doing things the hard
> way, then you can use a variation on
>
> bash -c 'my command here'
>
> as your command.

Instead of doing these kinds of work-arounds I'd just use the cwd
parameter of the exec resource as described in the type reference [1]

so e.g.

exec { 'make_sendmail':
command => '/usr/bin/make',
cwd => '/etc/mail'
}

If you have GNU make you can also ask the make command itself to change
the directory (-C dir, --directory=dir)

[1] http://docs.puppetlabs.com/references/latest/type.html#exec

-Stefan

Reply all
Reply to author
Forward
0 new messages