Hi All, Does anyone know how to add bash code to the exec resource? I was thinking I could add it to the command section. I thought I could run the code after I put the link command and options in. However, it didn''t work. My bash code has ''if'' statements with $ signs in it. I want to move block to a directory with its version so it can be sym linked to /block. move-block () { if [[ -s /block/block && ! -h /block ]]; then VERSION= /block/block -v | grep -oE "[0-9] {1,4}. [0-9] {1,3}. [0-9] {1,4}. [0-9] {1,4}" RENAMED_DIR=/block_$VERSION echo; echo "Moving System to $RENAMED_DIR" rm -rf $RENAMED_DIR mv /block $RENAMED_DIR fi Thanks in advance, -- 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.
On Tue, Sep 27, 2011 at 10:52:24AM -0700, Damien Bridges wrote:> Hi All, > > Does anyone know how to add bash code to the exec resource? I was > thinking I could add it to the command section. I thought I could run > the code after I put the link command and options in. However, it > didn''t work. My bash code has ''if'' statements with $ signs in it. I > want to move block to a directory with its version so it can be sym > linked to /block.Personally I''ve put shell scripting blocks in files (delivered by the puppet file type), and then have my exec both execute and depend on the existence of that file.> move-block () { > if [[ -s /block/block && ! -h /block ]]; then > VERSION= /block/block -v | grep -oE > "[0-9] {1,4}. [0-9] {1,3}. [0-9] {1,4}. [0-9] {1,4}" > RENAMED_DIR=/block_$VERSION > echo; echo "Moving System to > $RENAMED_DIR" > rm -rf $RENAMED_DIR > mv /block $RENAMED_DIR > fi > > > Thanks in advance, > > -- > 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.
You can''t do that, as the IF code is resolved by the puppet master before delivering the compiled catalog to the client. It looks like you want to just make a shell script, push it to the client and run it there. File { myshellscript: …, notify->Exec[''myshellscript''] } Exec { myshellscript: …} On Sep 27, 2011, at 10:52 AM, Damien Bridges wrote:> Does anyone know how to add bash code to the exec resource? I was > thinking I could add it to the command section. I thought I could run > the code after I put the link command and options in. However, it > didn''t work. My bash code has ''if'' statements with $ signs in it. I > want to move block to a directory with its version so it can be sym > linked to /block. > move-block () { > if [[ -s /block/block && ! -h /block ]]; then > VERSION= /block/block -v | grep -oE > "[0-9] {1,4}. [0-9] {1,3}. [0-9] {1,4}. [0-9] {1,4}" > RENAMED_DIR=/block_$VERSION > echo; echo "Moving System to > $RENAMED_DIR" > rm -rf $RENAMED_DIR > mv /block $RENAMED_DIR > fi > > > Thanks in advance, > > -- > 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. >-- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness -- 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.
On Sep 27, 12:52 pm, Damien Bridges <damien3...@gmail.com> wrote:> Hi All, > > Does anyone know how to add bash code to the exec resource? I was > thinking I could add it to the command section. I thought I could run > the code after I put the link command and options in. However, it > didn''t work. My bash code has ''if'' statements with $ signs in it. I > want to move block to a directory with its version so it can be sym > linked to /block. > move-block () { > if [[ -s /block/block && ! -h /block ]]; then > VERSION= /block/block -v | grep -oE > "[0-9] {1,4}. [0-9] {1,3}. [0-9] {1,4}. [0-9] {1,4}" > RENAMED_DIR=/block_$VERSION > echo; echo "Moving System to > $RENAMED_DIR" > rm -rf $RENAMED_DIR > mv /block $RENAMED_DIR > fi > > Thanks in advance,Use single quotes to delimit the command. This will inhibit Puppet from performing variable interpolation within, and will prevent Puppet from interpreting the embedded double quotes. Alternatively, you can use a backslash (\) to quote Puppet metacharacters within a string, just like in the shell. With that said, I have to agree with Damien that a script of any significant complexity ought to be written to a file on the client system and executed that way. For example, use a File resource to ensure your script present in /tmp, and run it via an Exec. Be sure to set up a relationship between the File and Exec resources to ensure that they are applied in the right order. John -- 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.
On Sep 27, 8:44 pm, Jo Rhett <jrh...@netconsonance.com> wrote:> You can''t do that, as the IF code is resolved by the puppet master before delivering the compiled catalog to the client. It looks like you want to just make a shell script, push it to the client and run it there.Sorry, no. If statements are not recognized inside resource declarations, which is where the shell code would need to be (preferably in the value of the ''command'' property, but possibly in the Exec title). Moreover, the shell code needs to be quoted anyway to feed it to Puppet, and doing so would prevent Puppet from interpreting anything in it even if it were somewhere where Puppet might otherwise consider doing so. John -- 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.
> On Sep 27, 8:44 pm, Jo Rhett <jrh...@netconsonance.com> wrote: >> You can''t do that, as the IF code is resolved by the puppet master before delivering the compiled catalog to the client. It looks like you want to just make a shell script, push it to the client and run it there.On Sep 28, 2011, at 7:03 AM, jcbollinger wrote:> Sorry, no. If statements are not recognized inside resource > declarations, which is where the shell code would need to be > (preferably in the value of the ''command'' property, but possibly in > the Exec title).Your second sentence is a conditional without a result but I think I know what you meant, and we were talking about different things. I read his example as wanting to use a shell test to determine whether to execute a puppet closure, which really isn''t possible. Yes, the entire if/do should be put inside a shell script and run locally ;-) -- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness -- 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.