Puppet facts

In Puppet, we can put several values as an environment variable with the help of a facter. Facter is a tool of puppet, which is used to keep the environment level variable. It is exactly like an environment variable of Bash or Linux. Sometimes the information that is stored in facts and the machine's environment variable may overlap. The key-value pair of the puppet is called fact. Each resource has its own facts, and we can construct custom facts in Puppet.

Puppet collects system information, called facts, by using the Facter tool. The facts are assigned as values to variables that you can use anywhere in your manifests. Puppet also sets some additional special variables, called built-in variables, which behave a lot like facts.

To see what variables are available from an agent, we can log in to the system running and execute:

#facter -p

processors => {

  count => 2,

  isa => "x86_64",

  models => [

    "Intel(R) Core(TM) i5-4310M CPU @ 2.70GHz",

    "Intel(R) Core(TM) i5-4310M CPU @ 2.70GHz"

  ],

  physicalcount => 1

}

puppetversion => 6.22.1

ruby => {

  platform => "x86_64-linux",

  sitedir => "/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.5.0",

  version => "2.5.9"

Note: This is only a small sample of the output.

To illustrate a basic use of facts, let’s create a new module by executing the following from the modules folder.

#pdk new module my_facts

We update modules/my_facts/manifests/my_class.pp as shown:

# @summary Use facts

#

# Use facts

#

# @example

#   include my_facts::my_class

class my_facts::my_class {

  file { '/tmp/my_facts':

    ensure  => 'present',

    content => "Another ${facts['os']['family']}",

    path    => '/tmp/my_facts',

  }

}

Github repo for:https://github.com/zippyopstraining/puppetfact/blob/main/my_class.pp

Facter command can be used to list all the different environment variables and their associated values. These collections of facts come with facter out-of-the-box and are referred to as core facts. One can add custom facts to the collection.



Relevant Blogs:

Puppet service resource 

Puppet facts 

Ansible cheat sheet 

Terraform execution in pipeline

Recent Comments

No comments

Leave a Comment