1、Augeas是什么?
Augeas基本上就是一个配置编辑工具。它以他们原生的格式解析配置文件并且将它们转换成树。配置的更改可以通过操作树来完成,并可以以原生配置文件格式保存配置。
2、查找一个配置节点
1 2 |
use Rex::Commands::Augeas; my $k = augeas exists => "/files/etc/hosts/*/ipaddr", "127.0.0.1"; |
3、增加一个配置项目
1 2 3 4 5 |
augeas insert => "/files/etc/hosts", label => "01", after => "/7", ipaddr => "192.168.2.23", canonical => "test"; |
结果:
1 2 3 4 5 6 7 8 |
192.168.1.1 tcentral localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.1 tv_central 192.168.1.1 centralmysq 192.168.1.1 centralmemecache 192.168.1.1 memecache01 192.168.1.1 redis 192.168.2.23 test |
3、导出配置文件
1 |
augeas dump => "/files/etc/hosts"; |
结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/files/etc/hosts /files/etc/hosts/1 /files/etc/hosts/1/ipaddr = " 192.168.1.1" /files/etc/hosts/1/canonical = "tv_central_platform01" /files/etc/hosts/1/alias[1] = "localhost" /files/etc/hosts/1/alias[2] = "localhost.localdomain" /files/etc/hosts/1/alias[3] = "localhost4" /files/etc/hosts/1/alias[4] = "localhost4.localdomain4" /files/etc/hosts/2 /files/etc/hosts/2/ipaddr = "::1" /files/etc/hosts/2/canonical = "localhost" /files/etc/hosts/2/alias[1] = "localhost.localdomain" /files/etc/hosts/2/alias[2] = "localhost6" /files/etc/hosts/2/alias[3] = "localhost6.localdomain6" /files/etc/hosts/3 |
4、修改文件
1 2 3 4 5 |
augeas modify => "/files/etc/ssh/sshd_config/PermitRootLogin" => "without-password", on_change => sub { service ssh => "restart"; }; |