« Previous -
Version 3/4
(diff) -
Next » -
Current version
Raphaël Pinson, 03/23/2012 08:31 am
Use /etc/mtab to get root device
Using Augeas in facts¶
Augeas is a configuration library that parses many file formats, representing the contents as a tree. This makes it useful for creating custom facts to retrieve configuration values from a client.
Pre-requisites¶
See Puppet_Augeas.
Working Examples¶
Augeas version¶
A simple example is in Facter itself, which retrieves the current version of the Augeas library.
Facter.add(:augeasversion) do
setcode do
begin
require 'augeas'
aug = Augeas::open('/', nil, Augeas::NO_MODL_AUTOLOAD)
ver = aug.get('/augeas/version')
aug.close
ver
rescue Exception
Facter.debug('ruby-augeas not available')
end
end
end
In this, it disables all loading of lenses because it’s retrieving a built in value. Full source code.
Getting the root filesystem device¶
This example gets the device name set in /etc/fstab of the root filesystem, perhaps to use in other Puppet file templates.
Facter.add(:rootdevice) do
setcode do
begin
require 'augeas'
aug = Augeas::open
dev = aug.get('/files/etc/mtab/*[file="/"]/spec')
aug.close
dev
rescue Exception
Facter.debug('ruby-augeas not available')
end
end
end