Hi Mike,

On Thu, Mar 24, 2016 at 11:59 AM, Mike Reed <mjohn.r...@gmail.com> wrote:

> Hey all,
>
> I'm a little stumped on why this fact is returning the incorrect value and
> I was hoping somebody would have some advice on this one.
>
> The fact is very basic and looks like this:
>
> # custom fact for detecting if machine is joined to the domain
> require 'facter'
>
> Facter.add(:pbis_joined) do
>   setcode do
>       domain_check = %q{/opt/pbis/bin/domainjoin-cli query | grep -i
> 'domain' | grep -i '<domain>'}
>     domain_return = Facter::Util::Resolution.exec(domain_check)
>     if domain_return == 0
>

Facter::Util::Resolution.exec returns the command's output as a string or
nil if the command failed.  Thus, I would expect this conditional
(`domain_return == 0`) to never evaluate to true because a string or a nil
can never equal 0.

What does the command output if you run it manually when you expect the
`pbis_joined` facter to be true?


>       pbis_joined = true
>     else
>       pbis_joined = false
>     end
>   end
> end
>

Also, the `pbis_joined` local variable serves no purpose here, as it is the
return value from the block that sets the fact's value.


>
> Regardless of whether the domain_check command is a success on the client,
> I always get a value of 'true' from the fact.  In fact, if I completely
> remove the /opt/pbis folder from the machine and run the fact again, I
> still get a value of 'true'.  Additionally, If I manually run the
> domain_check command on a machine that I know is not joined to the domain,
> I will still get a value of 'true' from the fact.
>
> I've also tried both single '=' and double '==' for the 'if domain_return'
> piece of the fact and neither seem to give me what I want.  I then thought
> that the domain_check object may not be considered an integer when
> comparing against the '0' so I added 'domain_return.to_i' and still got the
> same result.
>
> The code within the manifest that looks to this fact looks like this:  if
> ($::pbis_joined == true) {etc,etc,etc}
>
> I do have stringify_facts set to 'false' within puppet.conf on both the
> client and the master.
>
> Puppet version 3.6.2/Hiera version: 1.3.4
>
> Does anybody have any suggestions they can give me as to why I'm not
> getting the correct return value?
>
> As always, thanks to everybody for their help and support.
>
> Cheers,
>
> Mike
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/a1f8ece8-627b-478d-a108-97c91d76d654%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/a1f8ece8-627b-478d-a108-97c91d76d654%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CACZQQfP%3D7kHSwGRtM2_vfpe77%2B%3Dk%3Dg3YPeqQDraxbfBEz%2BvSQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to