custom fact issue

43 views
Skip to first unread message

Jemmorey

unread,
Mar 16, 2012, 10:56:49 AM3/16/12
to puppet...@googlegroups.com
Would anyone please assist me on this one?  This fact seems to work, but it doesn't return when called directly via facter --puppet noop, but the resulting facts end up in the reports.

I'm at wits end with this. Thanks!

<snip>
utc_hour = Facter::Util::Resolution.exec(%q</bin/date -u +"%H">).chomp


Facter.add(:noop) do
        setcode do
                environment = Facter.value(:environment)
                if environment.match("test|dev|qa")
                        result = false
                else
                        if utc_hour.match("01|02|03|04|05|06|07|08|09|10")
                                result = false
                        else
                                result = true
                        end
                end
                result
        end
end
</snip>

Guy Matz

unread,
Mar 16, 2012, 12:26:23 PM3/16/12
to puppet...@googlegroups.com
Hi!  Does the following do what you might expect?

fact_name = 'noop'
Facter.add(fact_name) do
  setcode do
    utc_hour = %x{/bin/date -u +"%H"}.chomp.to_i
    environment = Facter.value(:environment)
    #puts "env = #{environment}"

    if environment.match("test|dev|qa")
      result = "false"
    else
      if utc_hour.between?(1,10)

        result = "false"
      else
        result = "true"
      end
    end
    #puts "result #{result}"
    result
  end
end



--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Ubou1ggrLusJ.
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.

Jemmorey

unread,
Mar 16, 2012, 12:51:02 PM3/16/12
to puppet...@googlegroups.com
So far so good.  In test environment it actually reports when I run it. 

Thank you very much Guy.  I'll let you know how it goes in the environments which actually use noop.

Appreciate the help :)

Jordan


On Friday, March 16, 2012 12:26:23 PM UTC-4, Guy Matz wrote:
Hi!  Does the following do what you might expect?

fact_name = 'noop'
Facter.add(fact_name) do
  setcode do
    utc_hour = %x{/bin/date -u +"%H"}.chomp.to_i
    environment = Facter.value(:environment)
    #puts "env = #{environment}"
    if environment.match("test|dev|qa")
      result = "false"
    else
      if utc_hour.between?(1,10)
        result = "false"
      else
        result = "true"
      end
    end
    #puts "result #{result}"
    result
  end
end


To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.

Krzysztof Wilczynski

unread,
Mar 16, 2012, 2:55:03 PM3/16/12
to puppet...@googlegroups.com
Hi,

There is also no need to call "date" from within the shell saving on unnecessary fork, as Ruby can provide UTC time for you.

More concise version: https://gist.github.com/2051811

KW
Reply all
Reply to author
Forward
0 new messages