Sha256: 38ccb8208b7d3738fafb167dc3487841e9b071abe3065383c441195a379ceb3e

Contents?: true

Size: 1.18 KB

Versions: 74

Compression:

Stored size: 1.18 KB

Contents

# Onering Facts - Chef Properties
#   provides collection of Chef metadata
#
require 'json'

chef = Facter::Util::Resolution.exec("knife node show $(hostname -f) -c /etc/chef/client.rb -k /etc/chef/client.pem -u $(hostname -f) -F json 2> /dev/null | grep -v 'json_class' 2> /dev/null")


if chef
  begin
    chef = (JSON.load(chef) rescue {})

    unless chef.empty?
      Facter.add('chef_nodename') do
        setcode { chef['name'].to_s.strip.chomp.downcase rescue nil }
      end

      Facter.add('chef_version') do
        setcode { %x{chef-client --version}.chomp.split(' ').last.strip rescue nil }
      end

      Facter.add('chef_environment') do
        setcode { chef['environment'].to_s.strip.chomp.downcase rescue nil }
      end

      Facter.add('chef_runlist') do
        setcode { chef['run_list'].collect{|i| i.gsub('[','-').gsub(']','').gsub('::','-') } rescue nil }
      end

      Facter.add('chef_enabled') do
        setcode { !File.exists?('/outbrain/no_chef_run') }
      end

      Facter.add('chef_lastrun') do
        setcode { File.mtime('/etc/chef/last_ran_at').to_i rescue nil }
      end
    end
  rescue Exception => e
    STDERR.puts "#{e.name}: #{e.message}"
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
onering-report-0.6.13 lib/facter/onering_properties_chef.rb
onering-report-0.6.12 lib/facter/onering_properties_chef.rb
onering-report-0.6.11 lib/facter/onering_properties_chef.rb
onering-report-0.6.10 lib/facter/onering_properties_chef.rb
onering-report-0.6.9 lib/facter/onering_properties_chef.rb
onering-report-0.6.8 lib/facter/onering_properties_chef.rb
onering-report-0.6.7 lib/facter/onering_properties_chef.rb
onering-report-0.6.6 lib/facter/onering_properties_chef.rb
onering-report-0.6.5 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.65 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.64 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.63 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.62 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.61 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.60 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.59 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.58 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.57 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.56 lib/facter/onering_properties_chef.rb
onering-report-plugins-0.0.55 lib/facter/onering_properties_chef.rb