Puppet : How to use [facter Variable]2024/07/25 |
Facter variables which are the system settings are set automatically, It's possible to use them if need. |
|
[1] | Display facter variables. |
root@dlp:~# facter augeas => { version => "1.14.1" } disks => { vda => { size => "30.00 GiB", size_bytes => 32212254720, type => "hdd", vendor => "0x1af4" } } dmi => { bios => { release_date => "04/01/2014", vendor => "SeaBIOS", version => "1.16.3-2.el9" }, board => { manufacturer => "Red Hat", product => "RHEL" }, chassis => { type => "Other" }, manufacturer => "Red Hat", product => { name => "KVM", uuid => "9d39c7c3-c133-4d55-9205-d7e2a52ed960" } ..... ..... |
[2] | For example, if OS is [Ubuntu] and version is [24.04], apply [sample01] class, if version is not [24.04], apply [sample02] class, if OS is not [Ubuntu], apply [sample03] class. |
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/class.pp class sample01 { file { '/home/testfile9.txt': ensure => file, owner => 'root', group => 'root', mode => '0644', content => 'This is the puppet test file.', } } class sample02 { user { 'numbat': ensure => present, home => '/home/numbat', managehome => true, password => '$6$9GoE2liT6.P.U/a*****', } } class sample03 { file { '/home/testfile10.txt': ensure => file, owner => 'root', group => 'adm', content => 'test file #10', } } case $facts['os']['distro']['id'] { 'Ubuntu': { if $facts['os']['distro']['release']['major'] == '24.04' { include 'sample01' } else { include 'sample02' } } default: { include 'sample03' } } |
Sponsored Link |