Re: [Puppet Users] Re: using return value of a shell command as a puppet conditional

Daniel Pittman
Mon, 31 Jan 2011 23:46:32 -0000

On Mon, Jan 31, 2011 at 15:31, Ashley Gould <agould@ucop.edu>
wrote:
> On Mon, Jan 31, 2011 at 02:14:29PM -0800, jcbollinger wrote:
>> On Jan 31, 3:12 pm, Ashley Gould <ago...@ucop.edu> wrote:
>>
>> > if [ "/usr/bin/my_harmless_binary 2>&1
>/dev/null" ]; then
>> >   echo "my_harmless_binary succeeded"
>> >   cp /tmp/file1 /data/
>> > else
>> >   echo "my_harmless_binary FAILED"
>> > fi

[...]

> thank you both. my current task will use a file action. I''m trying
> to make puppet chose between alturnative versions of a file based on
> the result of a binary.
>
> I will work on the custom fact idea.  if such an issue is coming at
> me so early in the game, then I may as well get started learning
> how to build facts.

For what it is worth, I would say that the reason you are running into
this so early in the process is that you are not yet using puppet the
way it expects to be used – and, so, you run into these complications.

In the puppet model you would not ask the system about that binary,
then do something: you would say "machine A should have the binary,
and the something, while machine B should not have either".

The idea is that you declare, as far as possible, the state your
system should be – not what calculations you make to get from the
current to the desired state.  Fact should, ideally, be things about
the system that don''t vary (memory size, disk space) with state
changes, not questions about the current state.

So, I would strongly encourage you to "answer" the question about that
binary by deciding if the machine should have it installed, and if it
should work, and then implementing *that* in puppet.  The file install
bit should just fall into line after that.

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