So what if my previous example puppet custom fact easy as 1 2 3, needs to be run only on RedHat systems?
An additional line on the ruby file is added:
Facter.add('netuuid') do
confine :operatingsystem => "RedHat"
setcode do
Facter::Core::Execution.exec("echo `grep UUID /etc/sysconfig/network-scripts/ifcfg-eth0 | cut -c 7-42`")
end
end
Any core fact can be referenced with the colon and name of the fact
:operatingsystem
:osfamily
:kernel
etc.
Mostrando las entradas con la etiqueta facter. Mostrar todas las entradas
Puppet custom fact easy as 1, 2, 3.
After taking a careful reading at creating a custom fact. The solution was as follows to get the net uuid from /etc/sysconfig/network-scripts/ifcfg-eth0:
My custom fact stored on <modulepath>/<module>/lib/facter/netuuid.rb:
Facter.add('netuuid') do
setcode do
Facter::Core::Execution.exec("echo `grep UUID /etc/sysconfig/network-scripts/ifcfg-eth0 | cut -c 7-42`")
end
end
I have created the <modulepath>/<module>/templates/netuuid.erb with this content:
<%= netuuid %>
And then call my custom netuuid facter variable on a template inside a manifest:
class netuuid {
file { '/tmp/netuuid':
path => '/tmp/netuuid',
ensure => file,
content => template("module1/netuuid.erb"),
}
}
# cat /tmp/netuuid
e9ca61ca-7fee-4ce6-9728-f9eacd343b08
References:
https://docs.puppetlabs.com/guides/templating.html
https://docs.puppetlabs.com/facter/2.4/custom_facts.html
References:
https://docs.puppetlabs.com/guides/templating.html
https://docs.puppetlabs.com/facter/2.4/custom_facts.html
Suscribirse a:
Entradas (Atom)