puppet augeas 使用示例

puppet augeas 资源使用

使用augeas前提需要安装augeas 包。

  • augtool可执行命令路径:

puppet 3 版本      /usr/bin/augtool

puppet 4 版本  /opt/puppetlabs/puppet/bin/augtool

  • augtool 使用示例
    [root@puppetmaster ~]# augtool
    augtool> ls /augeas/load  #显示所有可用的资源
    Libvirtd_qemu/ = (none)
    Libvirtd_lxc/ = (none)
    Libvirtd/ = (none)
    VMware_Config/ = (none)
    Login_defs/ = (none)
    Networks/ = (none)
    Splunk/ = (none)
    Thttpd/ = (none)
    Odbc/ = (none)
    Nsswitch/ = (none)
    Netmasks/ = (none)
    ...

改变特定文件里参数值

augtool> set /files/etc/ssh/sshd_config/PermitrootLogin no
augtool> save

以树形结构来展示数据

cat /etc/hosts
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.181 puppet puppetmaster
192.168.200.181 files.puppetfans.cn
192.168.200.182 Xkefu
192.168.200.187 xkefu187

augtool> ls /files/etc/hosts
1/ = (none)
2/ = (none)
3/ = (none)
4/ = (none)
5/ = (none)
6/ = (none)

augtool> ls /files/etc/hosts/6
ipaddr = 192.168.200.187
canonical = xkefu187

查看augeas版本

augtool> ls /augeas/
root = /
context = /files
variables = (none)
version/ = 1.0.0
save = overwrite
span = disable
load/ = (none)
files/ = (none)

augeas 更多使用方法

Admin commands:
help - print help
load - (re)load files under /files
quit - exit the program
retrieve - transform tree into text
save - save all pending changes
store - parse text into tree
transform - add a file transform

Read commands:
dump-xml - print a subtree as XML
get - get the value of a node
label - get the label of a node
ls - list children of a node
match - print matches for a path expression
print - print a subtree
span - print position in input file corresponding to tree

Write commands:
clear - clear the value of a node
clearm - clear the value of multiple nodes
ins - insert new node
insert - insert new node (alias of 'ins')
mv - move a subtree
move - move a subtree (alias of 'mv')
rename - rename a subtree label
rm - delete nodes and subtrees
set - set the value of a node
setm - set the value of multiple nodes
touch - create a new node

Path expression commands:
defnode - set a variable, possibly creating a new node
defvar - set a variable

Type 'help <command>' for more information on a command

puppet augeas  使用方法及示例

在manifests 代码清单里使用augeas资源

augeas { "sshd_config":
changes => [
"set /files/etc/ssh/sshd_config/PermitRootLogin no",
],
}
augeas { "sshd_config":
context => "/files/etc/ssh/sshd_config",
changes => [
"set PermitRootLogin no",
"set Disable yes",
"rm PermitTTY yes",
"ins PermitTunnel no",
],
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注