Puppet : How to use [facter Variable]2024/09/12 |
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.0" } disks => { cd0 => { model => "QEMU QEMU DVD-ROM", size => "0 bytes", size_bytes => 0 }, vtbd0 => { size => "30.00 GiB", size_bytes => 32212254720 } } dmi => { bios => { release_date => "11/22/2023", vendor => "EDK II", version => "edk2-20231122-6.el9_4.2" }, manufacturer => "Red Hat", product => { name => "KVM", uuid => "5e2c10a0-2aba-4069-87c5-85953ba0dfba" } } facterversion => 4.7.1 ..... ..... |
[2] | For example, if OS is [FreeBSD] and major version is [14], apply [sample01] class, if major version is not [14], apply [sample02] class, if OS is not [FreeBSD], apply [sample03] class. |
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/class.pp class sample01 { file { '/home/testfile9.txt': ensure => file, owner => 'root', group => 'wheel', mode => '0644', content => 'This is the puppet test file.', } } class sample02 { user { 'dragonfly': ensure => present, home => '/home/dragonfly', managehome => true, password => '$6$v/Mo7qyDFJU9d*****', } } class sample03 { file { '/home/testfile10.txt': ensure => file, owner => 'root', group => 'wheel', content => 'test file #10', } } case $facts['os']['name'] { 'FreeBSD': { if $facts['os']['release']['major'] == '14' { include 'sample01' } else { include 'sample02' } } default: { include 'sample03' } } |
Sponsored Link |