Discussion:
[Puppet Users] pipes in command output
John T. Guthrie
2010-10-28 18:06:08 UTC
Permalink
Hello all,

While we can use generate() to get the output of a command into a puppet
manifest, it has limitations. In particular, no subshell is used to run
the command, so you can't use the pipe symbol, "|", to connect two
commands together. So how would one go about getting the output of
"command1 | command2" into a puppet variable in a manifest?

Thanks.

John Guthrie
***@limewire.com
--
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.
Jeff McCune
2010-10-28 18:26:16 UTC
Permalink
Post by John T. Guthrie
Hello all,
While we can use generate() to get the output of a command into a puppet
manifest, it has limitations.  In particular, no subshell is used to run
the command, so you can't use the pipe symbol, "|", to connect two
commands together.  So how would one go about getting the output of
"command1 | command2" into a puppet variable in a manifest?
I use wrapper scripts for this. Then have generate() call the wrapper script.

#! /bin/bash
# script to be used for generate() function
set -e
set -u
command1 | command2
--
Jeff McCune
http://www.puppetlabs.com/
--
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.
John T. Guthrie
2010-10-28 20:17:03 UTC
Permalink
Post by Jeff McCune
Post by John T. Guthrie
Hello all,
While we can use generate() to get the output of a command into a puppet
manifest, it has limitations. In particular, no subshell is used to run
the command, so you can't use the pipe symbol, "|", to connect two
commands together. So how would one go about getting the output of
"command1 | command2" into a puppet variable in a manifest?
I use wrapper scripts for this. Then have generate() call the wrapper script.
#! /bin/bash
# script to be used for generate() function
set -e
set -u
command1 | command2
I wish I had figured this out earlier. What also seems to work is the
following:

$my_variable = inline_template("<%= %x{command1 | command2} %>")

and this way, there is no need to distribute a file onto the
puppetmaster server. (I should note that I do give full path names to
both commands to be safe.)

Thank you very much for your help.

John Guthrie
***@limewire.com
--
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.
Jeff McCune
2010-10-29 03:19:52 UTC
Permalink
Post by John T. Guthrie
Hello all,
While we can use generate() to get the output of a command into a puppet
manifest, it has limitations.  In particular, no subshell is used to run
the command, so you can't use the pipe symbol, "|", to connect two
commands together.  So how would one go about getting the output of
"command1 | command2" into a puppet variable in a manifest?
I use wrapper scripts for this.  Then have generate() call the wrapper script.
#! /bin/bash
# script to be used for generate() function
set -e
set -u
command1 | command2
I wish I had figured this out earlier.  What also seems to work is the
$my_variable = inline_template("<%= %x{command1 | command2} %>")
That's quite slick. Thanks for following up to the list with the
alternative solution to the problem.
--
Jeff McCune
http://www.puppetlabs.com/
--
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.
Loading...