Skip to content

Instantly share code, notes, and snippets.

@fvoges
Created December 6, 2018 15:57
Show Gist options
  • Select an option

  • Save fvoges/3093aa8c61dc1954d3ddce1384b4d76d to your computer and use it in GitHub Desktop.

Select an option

Save fvoges/3093aa8c61dc1954d3ddce1384b4d76d to your computer and use it in GitHub Desktop.
Simple and structured custom fact examples
# This custom fact is confined to RedHat and derivatives and
# returns a simple fact (string)
Facter.add('centrify') do
confine Facter.value(:os)['family'] => 'RedHat'
setcode do
query = Facter::Core::Execution.execute('rpm -q --qf %{VERSION} CentrifyDC')
if query =~ /\d+\.\d+/
query
else
''
end
end
end
# This custom fact is confined to RedHat and derivatives and
# returns a structured fact (hash)
Facter.add('centrify') do
confine Facter.value(:os)['family'] => 'RedHat'
setcode do
query = Facter::Core::Execution.execute('rpm -q --qf %{VERSION} CentrifyDC')
if query =~ /\d+\.\d+/
{
"installed" => true,
"version" => query
}
else
{
"installed" => false
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment