Capture the output of exec command

9,822 views
Skip to first unread message

sateesh

unread,
Feb 21, 2012, 4:00:06 AM2/21/12
to Puppet Users
Hi,

I need to capture the output of an exec command in puppet manifest
variable. How can I do this.

Thanks in advance,
Sateesh B.

Paul Tötterman

unread,
Feb 21, 2012, 4:06:37 AM2/21/12
to puppet...@googlegroups.com
Hi Sateesh,

I need to capture the output of an exec command in puppet manifest
variable. How can I do this.

You cannot, since the manifest is compiled into a catalog on the puppet master and then the catalog is sent to the agent, which can be on a different machine, and only then is the command defined by the exec run.

Can you describe in more detail what you are actually trying to do? ( http://www.joelonsoftware.com/items/2008/01/22.html )

Cheers,
Paul

Alexander Swen

unread,
Feb 21, 2012, 4:18:09 AM2/21/12
to puppet...@googlegroups.com
You cannot, since the manifest is compiled into a catalog on the puppet master and then the catalog is sent to the agent, which can be on a different machine, and only then is the command defined by the exec run.

Ehrm, personly I would try:
exec {
  "put text in a file":
     command => "ls -la /etc>>/var/log/exec 2>&1";
or
     command => "ls -la /etc 2>&1 |tee /var/log/exec";

}

jcbollinger

unread,
Feb 21, 2012, 9:15:32 AM2/21/12
to Puppet Users


On Feb 21, 3:00 am, sateesh <bbalasate...@gmail.com> wrote:
> I need to capture the output of an exec command in puppet manifest
> variable. How can I do this.


As Paul observed, what you ask is inconsistent with Puppet's manner of
operation. How you should proceed instead depends on what you are
trying to accomplish.

A custom fact may provide what you are looking for: you can easily add
a custom fact to your system that will run a command on the node
*before* each catalog request, and provide the output as a fact
(accessible as a top-level Puppet variable). The documentation for
custom facts (http://docs.puppetlabs.com/guides/custom_facts.html)
provides an example of exactly that.


John
Reply all
Reply to author
Forward
0 new messages