Multiple external commands with puppet

7,041 views
Skip to first unread message

linuxbsdfreak

unread,
Feb 3, 2011, 11:23:20 AM2/3/11
to Puppet Users
Hi,

I want to execute multiple sed commands using the exec commands within
puppet. I can only setup one command parameter. For now i have to give
a long list of commands separated with ";" in order to use the single
command parameter. I know there are other efficient ways to solve this
problem. But my requirement is such i need to execute multiple
commands using the exec tool within puppet. Any one have who can give
me a hint how this problem could be solved.

NOTE: I need only the command parameter of exec. I dont need the other
parameters

Regards,
Kevin

Mark Stanislav

unread,
Feb 3, 2011, 11:29:55 AM2/3/11
to puppet...@googlegroups.com
Are you able to group these sed statements into a script and pass arguments to the script to do whatever set of executions are needed for that specific dataset?

I may not understand your 'need' exactly, either. Can you explain more of what you are trying to accomplish and less about what you've chosen to accomplish it with. May help stir-up better answers.

-Mark

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

Brian Gallew

unread,
Feb 3, 2011, 11:56:23 AM2/3/11
to puppet...@googlegroups.com
While it's perfectly appropriate to have multiple exec{} or a single exec{} with a multi-line command in your puppet manifest, once you reach a certain level of complexity you almost invariably want to switch to a file{"/usr/local/scripts": ...} exec{"/usr/local/scripts/doit": ...} model. The script can be trivially customized for the local system by puppet giving you great flexibility, while allowing more complex code paths or alternate languages to be easily used.

Daniel Pittman

unread,
Feb 3, 2011, 12:47:20 PM2/3/11
to puppet...@googlegroups.com

So, uh, your constraints are kind of strange, and suggest to me that
there is something else you are not telling us about what you are
trying to do that we should probably know. It would be a big help if
you could post the manifest that is causing trouble somewhere.

Anyhow, you can do this a bunch of ways; can you just pass your
multiple operations to the single sed instance? That should behave
the same way as multiple sed instances, in pretty much every case I
can imagine.

If that isn't possible for some reason, you can always fall back to
invoking the shell:

exec { "example":
command => "/bin/sh -c 'sed -e s@very@strange@ | sed -e s@choice@here@'"
}

Finally, as already noted, installing the script as an extra file
would be a really good way to make this easier to manage in future and
all.

Regards,
Daniel

PS: If you are trying to do multiple, independent things in the one
command, please don't. Running multiple exec operations to mutate the
file, and making sure they are all equipped with an appropriate
'unless' or 'onlyif' is much better in the long term.

--
⎋ Puppet Labs Developer – http://puppetlabs.com
✉ Daniel Pittman <dan...@puppetlabs.com>
✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775
♲ Made with 100 percent post-consumer electrons

Reply all
Reply to author
Forward
0 new messages