Home / Puppet / Puppet – What is Facter ? How it works ?

Puppet – What is Facter ? How it works ?

This article is going to brief about Puppet’s  Facter.  It’s a cross platform system profiling library  which helps to provide the similar formatted output on all the operating systems. Puppet agent uses facter to send the node information to the puppet server and this is required when you compile the node’s catalog.  Facter system profiling library  is part of the puppet agent package. By default , it ships with default core facts which are sufficient to manage the environment however you can also write the custom facts .

In simple term,

  • Facter is simple command line tool which provides the node specific information
  • This is just like “env” command in bash shell (which provides the set of variables) => (Not Exactly though).

 

Facter uses the OS commands and configuration files to generate the system information. For an example, to get the OS release details , it uses the lsb-release command.

 

Puppet Version:

[root@uapa1 facts.d]# puppet --version
4.3.1
[root@uapa1 facts.d]#

 

FACTER: 

1. Login to any of the puppet agent node.

2.Check the puppet agent service status.

[root@uapa1 ~]# /opt/puppetlabs/bin/facter --version
3.1.3 (commit 1aa380a82ec35b7f8e7e58fab627e74f93aaeff3)
[root@uapa1 ~]# systemctl status puppet.service
● puppet.service - Puppet agent
 Loaded: loaded (/usr/lib/systemd/system/puppet.service; enabled; vendor preset: disabled)
 Active: active (running) since Mon 2016-02-08 14:00:45 EST; 21h ago
 Main PID: 2823 (puppet)
 CGroup: /system.slice/puppet.service
 └─2823 /opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/puppet/bin/puppet agent --no-daemonize

3. Facter is part of puppet agent package. You can verify it using following command.

[root@uapa1 ~]# rpm -qf /opt/puppetlabs/facter
puppet-agent-1.3.2-1.el7.x86_64
[root@uapa1 ~]#

 

4. Check the facter version.

[root@uapa1 ~]# facter --version
3.1.3 (commit 1aa380a82ec35b7f8e7e58fab627e74f93aaeff3)
[root@uapa1 ~]#

 

5. Execute the “facter” command and see what it provides.

[root@uapa1 ~]# facter
augeas => {
  version => "1.4.0"
}
disks => {
  fd0 => {
    size => "4.00 KiB",
    size_bytes => 4096
  },
  sda => {
    model => "VMware Virtual S",
    size => "20.00 GiB",
    size_bytes => 21474836480,
    vendor => "VMware,"
  },
  sdb => {
    model => "VMware Virtual S",
    size => "512.00 MiB",
    size_bytes => 536870912,
    vendor => "VMware,"
  },
  sr0 => {
    model => "VMware SATA CD00",
    size => "1.00 GiB",
    size_bytes => 1073741312,
    vendor => "NECVMWar"
  },
  sr1 => {
    model => "VMware SATA CD01",
    size => "3.77 GiB",
    size_bytes => 4043309056,
    vendor => "NECVMWar"
  }
}
dmi => {
  bios => {
    release_date => "07/31/2013",
    vendor => "Phoenix Technologies LTD",
    version => "6.00"
  },
  board => {
    manufacturer => "Intel Corporation",
    product => "440BX Desktop Reference Platform",
    serial_number => "None"
  },
  chassis => {
    asset_tag => "No Asset Tag",
    type => "Other"
  },
  manufacturer => "VMware, Inc.",
  product => {
    name => "VMware Virtual Platform",
    serial_number => "VMware-56 4d 16 2a 57 dc 86 3e-66 dc 48 c2 67 da 2e f9",
    uuid => "564D162A-57DC-863E-66DC-48C267DA2EF9"
  }
}
facterversion => 3.1.3
filesystems => xfs
identity => {
  gid => 0,
  group => "root",
  uid => 0,
  user => "root"
}
is_virtual => true
kernel => Linux
kernelmajversion => 3.10
kernelrelease => 3.10.0-327.el7.x86_64
kernelversion => 3.10.0
load_averages => {
  15m => 0.05,
  1m => 0,
  5m => 0.02
}
memory => {
  swap => {
    available => "2.00 GiB",
    available_bytes => 2147479552,
    capacity => "0%",
    total => "2.00 GiB",
    total_bytes => 2147479552,
    used => "0 bytes",
    used_bytes => 0
  },
  system => {
    available => "3.21 GiB",
    available_bytes => 3441639424,
    capacity => "13.26%",
    total => "3.70 GiB",
    total_bytes => 3967950848,
    used => "501.93 MiB",
    used_bytes => 526311424
  }
}
mountpoints => {
  / => {
    available => "7.46 GiB",
    available_bytes => 8006574080,
    capacity => "57.39%",
    device => "/dev/mapper/rhel-root",
    filesystem => "xfs",
    options => [
      "rw",
      "relatime",
      "attr2",
      "inode64",
      "noquota"
    ],
    size => "17.50 GiB",
    size_bytes => 18788384768,
    used => "10.04 GiB",
    used_bytes => 10781810688
  },
  /boot => {
    available => "284.02 MiB",
    available_bytes => 297811968,
    capacity => "42.82%",
    device => "/dev/sda1",
    filesystem => "xfs",
    options => [
      "rw",
      "relatime",
      "attr2",
      "inode64",
      "noquota"
    ],
    size => "496.67 MiB",
    size_bytes => 520794112,
    used => "212.65 MiB",
    used_bytes => 222982144
  }
}
networking => {
  dhcp => "192.168.203.160",
  fqdn => "UAPA1",
  hostname => "uapa1",
  interfaces => {
    br0 => {
      bindings => [
        {
          address => "192.168.203.134",
          netmask => "255.255.255.0",
          network => "192.168.203.0"
        }
      ],
      bindings6 => [
        {
          address => "fe80::62:40ff:fe07:2913",
          netmask => "ffff:ffff:ffff:ffff::",
          network => "fe80::"
        }
      ],
      dhcp => "192.168.203.160",
      ip => "192.168.203.134",
      ip6 => "fe80::62:40ff:fe07:2913",
      mac => "00:0c:29:da:2e:f9",
      mtu => 1500,
      netmask => "255.255.255.0",
      netmask6 => "ffff:ffff:ffff:ffff::",
      network => "192.168.203.0",
      network6 => "fe80::"
    },
    eno16777736 => {
      dhcp => "192.168.203.160",
      mac => "00:0c:29:da:2e:f9",
      mtu => 1500
    },
    lo => {
      bindings => [
        {
          address => "127.0.0.1",
          netmask => "255.0.0.0",
          network => "127.0.0.0"
        }
      ],
      bindings6 => [
        {
          address => "::1",
          netmask => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
          network => "::1"
        }
      ],
      ip => "127.0.0.1",
      ip6 => "::1",
      mtu => 65536,
      netmask => "255.0.0.0",
      netmask6 => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
      network => "127.0.0.0",
      network6 => "::1"
    },
    virbr0 => {
      bindings => [
        {
          address => "192.168.122.1",
          netmask => "255.255.255.0",
          network => "192.168.122.0"
        }
      ],
      ip => "192.168.122.1",
      mac => "52:54:00:16:bc:24",
      mtu => 1500,
      netmask => "255.255.255.0",
      network => "192.168.122.0"
    },
    virbr0-nic => {
      mac => "52:54:00:16:bc:24",
      mtu => 1500
    }
  },
  ip => "192.168.203.134",
  ip6 => "fe80::62:40ff:fe07:2913",
  mac => "00:0c:29:da:2e:f9",
  mtu => 1500,
  netmask => "255.255.255.0",
  netmask6 => "ffff:ffff:ffff:ffff::",
  network => "192.168.203.0",
  network6 => "fe80::",
  primary => "br0"
}
os => {
  architecture => "x86_64",
  distro => {
    codename => "Maipo",
    description => "Red Hat Enterprise Linux Server release 7.2 (Maipo)",
    id => "RedHatEnterpriseServer",
    release => {
      full => "7.2",
      major => "7",
      minor => "2"
    },
    specification => ":core-4.1-amd64:core-4.1-noarch"
  },
  family => "RedHat",
  hardware => "x86_64",
  name => "RedHat",
  release => {
    full => "7.2",
    major => "7",
    minor => "2"
  },
  selinux => {
    enabled => false
  }
}
partitions => {
  /dev/mapper/rhel-root => {
    filesystem => "xfs",
    mount => "/",
    size => "17.51 GiB",
    size_bytes => 18798870528,
    uuid => "6eddf97b-99d2-4cde-b08c-98967063a482"
  },
  /dev/mapper/rhel-swap => {
    filesystem => "swap",
    size => "2.00 GiB",
    size_bytes => 2147483648,
    uuid => "3b2d06f7-b655-4de9-b1b5-41509adf3029"
  },
  /dev/sda1 => {
    filesystem => "xfs",
    mount => "/boot",
    size => "500.00 MiB",
    size_bytes => 524288000,
    uuid => "ecc9aba3-4b15-49ef-b571-b65beaa3ca46"
  },
  /dev/sda2 => {
    filesystem => "LVM2_member",
    size => "19.51 GiB",
    size_bytes => 20949499904,
    uuid => "uZymRJ-CiuQ-AA8a-lZMP-0pls-zu9C-cdcqhk"
  }
}
path => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin:/root/bin
processors => {
  count => 2,
  isa => "x86_64",
  models => [
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz",
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz"
  ],
  physicalcount => 1
}
ruby => {
  platform => "x86_64-linux",
  sitedir => "/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0",
  version => "2.1.7"
}

system_uptime => {
  days => 0,
  hours => 21,
  seconds => 76292,
  uptime => "21:11 hours"
}
timezone => EST
virtual => vmware
[root@uapa1 ~]#

Facter provides all the available facts about system. If no facts are specifically asked for, then all facts will be returned.

 

6. Would you like to use facter to fetch specific information?  Just provide the specific fact like following.

  • To see the CPU information,
[root@uapa1 ~]# facter processors
{
  count => 2,
  isa => "x86_64",
  models => [
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz",
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz"
  ],
  physicalcount => 1
}
[root@uapa1 ~]#

 

  • To check the OS family,
[root@uapa1 ~]# facter osfamily
RedHat
[root@uapa1 ~]#

 

  • To check other OS details,
[root@uapa1 ~]# facter os
{
  architecture => "x86_64",
  distro => {
    codename => "Maipo",
    description => "Red Hat Enterprise Linux Server release 7.2 (Maipo)",
    id => "RedHatEnterpriseServer",
    release => {
      full => "7.2",
      major => "7",
      minor => "2"
    },
    specification => ":core-4.1-amd64:core-4.1-noarch"
  },
  family => "RedHat",
  hardware => "x86_64",
  name => "RedHat",
  release => {
    full => "7.2",
    major => "7",
    minor => "2"
  },
  selinux => {
    enabled => false
  }
}
[root@uapa1 ~]#

 

7. Let’s see how the output differs when you run the same facter command from Ubuntu.

root@uacloud:~# facter processors
{
  count => 2,
  isa => "x86_64",
  models => [
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz",
    "Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz"
  ],
  physicalcount => 1
}
root@uacloud:~#

 

  • OSFamily:
root@uacloud:~# facter osfamily
Debian
root@uacloud:~#

 

  • OS details:
root@uacloud:~# facter os
{
  architecture => "amd64",
  distro => {
    codename => "trusty",
    description => "Ubuntu 14.04.3 LTS",
    id => "Ubuntu",
    release => {
      full => "14.04",
      major => "14.04"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Ubuntu",
  release => {
    full => "14.04",
    major => "14.04"
  },
  selinux => {
    enabled => false
  }
}
root@uacloud:~#

 

We are just using same facter commands irrespective of any  operating systems and it provides the output in same format. Just the results are different (Ex: OS family) . These all facts are required when you are classifying the nodes. For an example, if you want to install the Apache on Redhat & Debian systems,  you need to specify the packages names as “httpd” & “apache” respectively. In Module, we will just define that if it’s a redhat OS family , use “httpd” and if it’s a Debian family , use “apache” to install the packages.

 

Custom Fact:

Let’s write the first custom fact.

1.Login to any of the puppet agent node.

2.Navigate to “/opt/puppetlabs/facter/facts.d” directory .

 

3. Create a simple shell script to define the variable and make it executable.

[root@uapa1 facts.d]# cat env_custom-facts.sh
#!/bin/bash
echo "hostgroup=UA"
echo "environment=SBX"
[root@uapa1 facts.d]#
[root@uapa1 facts.d]# chmod +x env_custom-facts.sh

We have configured the new fact for this puppet agent.

 

4. Let’s test it . Use the facter command to display the hostgroup.

[root@uapa1 facts.d]# facter hostgroup
UA
[root@uapa1 facts.d]#

 

You can also see that environment fact also defined.

[root@uapa1 facts.d]# facter environment
SBX
[root@uapa1 facts.d]#
[root@uapa1 facts.d]# facter |egrep "hostgroup|environment"
environment => SBX
hostgroup => UA
[root@uapa1 facts.d]#

This is how you can write own fact to classify the puppet agents.

 

Hope this article is informative to you . Share it ! Comment it !! Be Sociable !!!

VMTURBO-CLOUD-CAPACITY

Leave a Reply

Your email address will not be published. Required fields are marked *