Joining two commands in exec

36 views
Skip to first unread message

John S

unread,
Apr 13, 2014, 11:24:22 PM4/13/14
to puppet...@googlegroups.com
Hi All,
 
I have created a puppet manifest for creating hadoop folder for each user  and changing the ownership for each user.Am giving the user with title parameter from nodes.pp
 
I was trying to execute two commands using exec parameter, but its executing the first command, second command it is not executing .  Dont know if am following the correct syntax . please help .
 
Attached below complete manifest module .
 
define hadoop::dir {
exec { "/usr/bin/hadoop fs -mkdir /user/$title && /usr/bin/hadoop fs -chown $title:title /user/$title ":
    creates => "/usr/bin/hadoop fs -ls /user/$title",
}
regards
John

Matthias Saou

unread,
Apr 14, 2014, 7:21:19 AM4/14/14
to puppet...@googlegroups.com
On Sun, 13 Apr 2014 20:24:22 -0700 (PDT)
John S <bun...@gmail.com> wrote:

> define hadoop::dir {
> exec { "/usr/bin/hadoop fs -mkdir /user/$title && /usr/bin/hadoop fs
> -chown $title:title /user/$title ":
> creates => "/usr/bin/hadoop fs -ls /user/$title",
> }

I'm unsure how the "creates" will behave here, as it expects a local
file (or directory) to check for existence, not a command.

What you need to double check is the exit status of all of the commands
you are running, as well as change the "creates" to "unless", probably.

Run : /usr/bin/hadoop fs -ls /user/foo; echo $?

If you see 0 then the exec will no longer run when using "unless".

Run : /usr/bin/hadoop fs -mkdir /user/foo; echo $?

You'll need to see 0 when the HDFS directory didn't exist in order for
the '&&' to then execute to 2nd command.

HTH,
Matthias

--
Matthias Saou ██ ██
██ ██
Web: http://matthias.saou.eu/ ██████████████
Mail/XMPP: matt...@saou.eu ████ ██████ ████
██████████████████████
GPG: 4096R/E755CC63 ██ ██████████████ ██
8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██
21A9 7A51 7B82 E755 CC63 ████ ████

jcbollinger

unread,
Apr 14, 2014, 9:05:42 AM4/14/14
to puppet...@googlegroups.com
As Matthias said, the "creates" parameter wants a file name, not a command.  I don't see why Puppet would handle it any other way than by testing for a file with that strange name, which is surely not what you wanted.  Instead, choose a characteristic file and name only it.

But that's not the reason for the behavior you observe.  Matthias is also right that the second command in that '&&' list will not run if the first exits with nonzero status.  ALSO, however, the second will not run if Puppet uses the 'posix' Exec provider (instead, that provider will pass the '&&', subsequent command, and command-line parameters as additional parameters to the first command).  If you want to use a shell to run your Exec 'command' (as apparently you do), then you should specify "provider => 'shell'" as well.


John

Reply all
Reply to author
Forward
0 new messages