FAQ
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:
<code>
exec{$one_install_script:
require => File[$one_install_script],
onlyif => "[ \"$(/bin/ls -A $one_location)\" ] && exit 1 || exit
0"
}

</code>

It failed with following error:

<error>
err: Failed to apply catalog: Parameter onlyif failed: '[ "$(/bin/ls -
A /srv/cloud/one)" ] && exit 1 || exit 0' is not qualified and no
path was specified. Please qualify the command or specify a path.
</error>

A bash script with above one-liner worked fine though.
<code>
exec{$one_install_script:
require => File[$one_install_script],
onlyif => "/tmp/is-dir-empty.sh $one_location"
</code>

The bash script approach works fine for me. However I am not sure what
is wrong with the one-liner command. Is $(cmd) command substitution or
built-in function 'exit' a problem? Any pointers will be really
helpful.

--
Thanks,
Shantanu

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

Search Discussions

  • Florian Koch at Apr 25, 2012 at 4:03 pm
    Hi,

    you need to add provider => shell to your exec to get the subshell working

    regards Florian
    On Wed, Apr 25, 2012 at 6:01 PM, 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:
    <code>
    exec{$one_install_script:
    require => File[$one_install_script],
    onlyif => "[ \"$(/bin/ls -A $one_location)\" ] && exit 1 || exit
    0"
    }

    </code>

    It failed with following error:

    <error>
    err: Failed to apply catalog: Parameter onlyif failed: '[ "$(/bin/ls -
    A /srv/cloud/one)" ] && exit 1 || exit 0' is not qualified and no
    path was specified. Please qualify the command or specify a path.
    </error>

    A bash script with above one-liner worked fine though.
    <code>
    exec{$one_install_script:
    require => File[$one_install_script],
    onlyif => "/tmp/is-dir-empty.sh $one_location"
    </code>

    The bash script approach works fine for me. However I am not sure what
    is wrong with the one-liner command. Is $(cmd) command substitution or
    built-in function 'exit' a problem? Any pointers will be really
    helpful.

    --
    Thanks,
    Shantanu

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

    On Apr 25, 11:03 am, Florian Koch wrote:
    Hi,

    you need to add provider => shell to your exec to get the subshell working

    regards Florian
    Thanks Florian. The provider parameter took care of shell built-ins
    and path as well.

    --
    Shantanu

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

    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:
    <code>
    exec{$one_install_script:
    require => File[$one_install_script],
    onlyif => "[ \"$(/bin/ls -A $one_location)\" ]&& exit 1 || exit
    0"
    }
    Puppet wont let you run commands that dont have fully qualified paths,
    try adding this and it should work...

    path => "/bin"

    Craig

    --
    Craig Dunn | http://www.craigdunn.org
    Yahoo/Skype: craigrdunn | Twitter: @crayfishX

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

    On Apr 25, 11:46 am, 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:
    <code>
    exec{$one_install_script:
    require =>  File[$one_install_script],
    onlyif =>  "[ \"$(/bin/ls -A  $one_location)\" ]&&  exit 1 || exit
    0"
    }
    Puppet wont let you run commands that dont have fully qualified paths,
    try adding this and it should work...

    path => "/bin"
    Almost worked, it didn't fail while applying the catalog however it
    failed with following error.

    {{{
    Exec[/tmp/one_install_script]: Could not evaluate: Could not find
    command '['
    }}}

    As suggested by Florian using 'provider => shell' takes care of PATH
    and shell built-ins as well.

    --
    Thanks,
    Shantanu

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

    On Wed, 25 Apr 2012 10:29:23 -0700 (PDT) Shantanu wrote:

    On Apr 25, 11:46 am, 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:
    <code>
    exec{$one_install_script:
    require =>  File[$one_install_script],
    onlyif =>  "[ \"$(/bin/ls -A  $one_location)\" ]&&  exit 1
    exit 0"
    }
    Puppet wont let you run commands that dont have fully qualified
    paths, try adding this and it should work...

    path => "/bin"
    Almost worked, it didn't fail while applying the catalog however it
    failed with following error.

    {{{
    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 => [ '/bin', '/usr/bin' ] would probably have worked.
    As suggested by Florian using 'provider => 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 => "[ -d $one_location -a -z \"$(ls -A $one_location)\" ]"

    Matthias

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedApr 25, '12 at 4:02p
activeApr 26, '12 at 10:07a
posts6
users4
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase