我对Augeas相当陌生,但我被告知这是用puppet修改configuration的工具。
我试图创build一个简单的类,如果它不存在,添加一行到/ etc / hosts。
augeas { "test_config": context => "/files/etc/hosts/01/", changes => [ "set ipaddr 192.168.100.3", "set canonical test.localdomain", "set alias[1] test", ],
这创build了我后面的路线。
hosts文件看起来像这样
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
因为我不想重复,我在augtool中创build了一个匹配行来获得匹配。
augtool> match / files / etc / hosts / 3 / alias / files / etc / hosts / 3 / alias = test
我目前的configuration似乎是不可预知的充其量
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'", }
任何人都可以帮助我在这个方向上正确的方向吗?
要pipe理主机条目,您应该使用host资源types。
这种types默认使用Puppet,但你也可以通过使用augeasproviders模块(尤其是augeasproviders-base模块)将它与Augeas(我会推荐)一起使用。
为什么不使用exec资源?
exec{'serverfault demo': command => 'echo 192.168.100.3 test.localdomain >> /etc/hosts', unless => 'grep test.localdomain /etc/hosts', path => ['/bin','/usr/bin'], }
这将运行echo命令,并且只有在/ etc / hosts中不存在192.168.100.3 test.localdomain行时才添加该行。