Facter is a utility which collects and displays facts about the system such as operatingsystem, ip, MAC address, machine's hardware information.
Point to note:
- If no specific facts are specifically asked for, then all facts will be returned.
- We can add our custom facts too.
[root@rhel6 ~]# facter
architecture => x86_64
augeasversion => 0.9.0
domain => sunny.com
facterversion => 1.6.18
fqdn => rhel6.sunny.com
hardwareisa => x86_64
hardwaremodel => x86_64
hostname => rhel6
id => root
interfaces => eth1,lo
ipaddress => 192.168.122.173
ipaddress_eth1 => 192.168.122.173
ipaddress_lo => 127.0.0.1
............
............
[root@rhel6 ~]#
Now suppose you just need to see the hostname via facter command.
[root@rhel6 ~]# facter hostname
rhel6
[root@rhel6 ~]#
It works well with grep command too.
[root@rhel6 ~]# facter | grep memory
memoryfree => 188.36 MB
memorysize => 280.95 MB
memorytotal => 280.95 MB
[root@rhel6 ~]#
The values returned by facter is very valuable information and used couple of time by the manifest which we write.
For instance:
case $operatingsystem {
CentOS , RedHat , Fedora: {
$service_name = 'ntpd'
$conf_file = 'ntp.conf.el'
}
Debian, Ubuntu: {
$service_name = 'ntp'
$conf_file = 'ntp.conf.debian'
}
In above example the value of
$operatingsystem will be fetched by the help of facter the the code will be processed as per that value.
If in-case the value of $operatingsystem is RedHat or CentOS or Fedora then it will use $service_name as ntpd and $conf_file as ntp.conf.el and if the value of $operatingsystem is Debian or Ubuntu then it will use $service_name as ntp and $conf_file as ntp.conf.debian, So basically the use of values of facter are really of importance while writing the manifests.
There are various options available with the facter command, like firing the command with -d enables debugging information on our CLI.
[root@rhel6 ~]# facter -d
Not an EC2 host
value for arp is still nil
value for sshecdsakey is still nil
Found no suitable resolves of 2 for processor
.....
.....
.....
uptime_hours => 0
uptime_seconds => 2529
virtual => kvm
[root@rhel6 ~]#
Adding -p loads the puppet libraries too means if you have added any custom facts they will also be displayed on the CLI.
[root@rhel6 ~]# facter -p
Adding -y loads the puppet libraries too means if you have added any custom facts they will also be displayed on the CLI.
[-v|--version] ==> Adding -v tells us the version of facter installed in your machine.
[-y|--yaml] ==>Adding -y loads the facter output in the form of yaml.
[-j|--json] ==>Adding -j loads the facter output in the form of json.
For more information you can check facter's man page.
Comments
Post a Comment