I'm fairly new to Augeas, but I've been told it is the tool for modifying config with puppet.
I'm trying to create a simple class that adds a line to /etc/hosts if it doesn't already exist.
augeas { "test_config":
context => "/files/etc/hosts/01/",
changes => [
"set ipaddr 192.168.100.3",
"set canonical test.localdomain",
"set alias[1] test",
],
This creates the line i'm after.
The hosts file looks like this
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.3 test.localhost test
192.168.0.4 badger.oam.eeint.co.uk badger
As I don't want duplicates, I created a match line in augtool to get match.
augtool> match /files/etc/hosts/3/alias
/files/etc/hosts/3/alias = test
My current config seems to be unpredictable at best
augeas { "test_config":
context => "/files/etc/hosts/*/",
changes => [
"set ipaddr 192.168.100.3",
"set canonical test.localdomain",
"set alias[1] test",
],
onlyif => "match alias 'test'",
}
Can anyone help nudge me in the right direction on this one?
Best Answer
To manage host entries, you should use the
host
resource type.This type comes by default with Puppet, but you can also use it with Augeas (which I would recommend) by using the augeasproviders module (and in particular, the augeasproviders-base module).