Received: by 10.180.105.71 with SMTP id gk7mr4435418wib.0.1335434834455; Thu, 26 Apr 2012 03:07:14 -0700 (PDT) X-BeenThere: puppet-users@googlegroups.com Received: by 10.180.7.9 with SMTP id f9ls8276619wia.2.canary; Thu, 26 Apr 2012 03:07:04 -0700 (PDT) Received: by 10.181.13.198 with SMTP id fa6mr959270wid.0.1335434824708; Thu, 26 Apr 2012 03:07:04 -0700 (PDT) Received: by 10.181.13.198 with SMTP id fa6mr959269wid.0.1335434824699; Thu, 26 Apr 2012 03:07:04 -0700 (PDT) Return-Path: Received: from mail.marmotte.net (bubble-i2.marmotte.net. [94.23.82.212]) by gmr-mx.google.com with ESMTP id n4si6946003wiw.0.2012.04.26.03.07.04; Thu, 26 Apr 2012 03:07:04 -0700 (PDT) Received-SPF: neutral (google.com: 94.23.82.212 is neither permitted nor denied by best guess record for domain of matth...@saou.eu) client-ip=94.23.82.212; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 94.23.82.212 is neither permitted nor denied by best guess record for domain of matth...@saou.eu) smtp.mail=matth...@saou.eu X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on burst03.marmotte.ici X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,RDNS_NONE autolearn=no version=3.3.1 Received: from r2d2.marmotte.net (unknown [80.169.244.43]) by mail.marmotte.net (marmotte mail daemon) with ESMTP id 9704D5501E0 for ; Thu, 26 Apr 2012 12:07:03 +0200 (CEST) Date: Thu, 26 Apr 2012 12:07:02 +0200 From: Matthias Saou To: puppet-users@googlegroups.com Subject: Re: [Puppet Users] Re: exec's onlyif parameter fails for a bash one-liner Message-ID: <20120426120702.3847f8d9@r2d2.marmotte.net> In-Reply-To: References: <44fc11ab-eb3d-467e-8560-956eafc80948@w5g2000vbp.googlegroups.com> <4F982A6B.3070202@craigdunn.org> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.18.9; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV using ClamSMTP On Wed, 25 Apr 2012 10:29:23 -0700 (PDT) Shantanu wrote: >=20 > On Apr 25, 11:46=A0am, Craig Dunn wrote: > > On 25/04/2012 17:01, Shantanu wrote: > > > > > > > > > I would like to 'exec' an installation script 'onlyif' an > > > installation directory is empty. I tried using following bash > > > one-liner however it didn't work: > > > > > > =A0 =A0exec{$one_install_script: > > > =A0 =A0 =A0require =3D> =A0File[$one_install_script], > > > =A0 =A0 =A0onlyif =3D> =A0"[ \"$(/bin/ls -A =A0$one_location)\" ]&& = =A0exit 1 > > > || exit 0" > > > =A0 =A0} > > > > Puppet wont let you run commands that dont have fully qualified > > paths, try adding this and it should work... > > > > path =3D> "/bin" > > >=20 > Almost worked, it didn't fail while applying the catalog however it > failed with following error. >=20 > {{{ > Exec[/tmp/one_install_script]: Could not evaluate: Could not find > command '[' > }}} That's because [ is usually in /usr/bin, not /bin : $ which [ /usr/bin/[ so path =3D> [ '/bin', '/usr/bin' ] would probably have worked. > As suggested by Florian using 'provider =3D> shell' takes care of PATH > and shell built-ins as well. That's probably just as good a solution. On an unrelated note, something like the following might be more what you're trying to achieve, since you have a somewhat reversed logic and aren't checking for the directory's existence at all (untested) : onlyif =3D> "[ -d $one_location -a -z \"$(ls -A $one_location)\" ]" Matthias