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

Daniel Pittman
Tue, 01 Feb 2011 02:27:20 -0000

On Mon, Jan 31, 2011 at 18:14, Ashley Gould <agould@ucop.edu>
wrote:
>> > 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.

[...]

> You caught me.  I''m a recoveing cfengine junky.  It will take a
while
> to stop thinking in terms of making actions dependent on client''s
> membership in a (cf) class.
>
> So here are the specifics of what I''m trying to do in this
particular
> task.  I welcome any ideas on following the puppet way:

OK.  So, in the circumstances, where membership of the domain with
centrifyDC is *not* managed by puppet, your use of a fact is the right
thing to do.  For better or worse, "am I joined to a domain" is a fact
about the machine that comes from outside of puppet.

In the longer term I would hope to have that information pushed out
from the puppet system, so that if a node *should* be joined with
centrifyDC puppet will make it so, but until then what you have is
great.

[...]

> My first fact (I am so proud):
>
> # adinfo.rb
> # Mon Jan 31 15:54:02 PST 2011
> # agould@ucop.edu
> #
> # a custom fact returning the centrify zone
>
> if FileTest.exists?("/usr/bin/adinfo")
>        Facter.add(:adinfo) do
>                setcode do
>                        %x{/usr/bin/adinfo --zone}.chomp
>                end
>        end
> end

Perfect.  You even handled the case where centrify isn''t installed
correctly, so this will not blow up random other systems. :)

Probably the one thing to watch out for is that *only* the empty
string is reliably false in puppet, in context, so you can''t just
return the (Ruby) false value or something.  That gets turned into a
string, and the string "false" is actually true in puppet.  Just for
the future. :)

> class pam {
>        file { "/etc/pam.d":
>                owner   => root, group   => root, mode    => 644,
>                if $adinfo {
>                        source  => "puppet:///pam/centrify",
>                } else {
>                        source  => "puppet:///pam/no_centrify",
>                }

You actually want:

    mode => 0644,
    $adinfo ? {
      '''' => ''.../no_centrify'',
     default => ''.../centrify''  # Assuming that "any
value" means "in a domain"
    },
    whatever => else

The if statement is not used in that context, only a case statement.

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