使用Augeas类型:
augeas { 'remove_ini_header':
incl => '/etc/example.ini',
lens => 'IniFile.lns_loose',
changes => 'rm section[. = "header"]',
}
要打破这一点,首先我用内置的IniFile.lns_loose
镜头(即INI文件“通用”松解析)和augtool
看到树的当前状态:
$ augtool -t "IniFile.lns_loose incl /etc/example.ini"
augtool> print /files/etc/example.ini
/files/etc/example.ini
/files/etc/example.ini/section = "header"
/files/etc/example.ini/section/ip = "'1.1.1.1'"
/files/etc/example.ini/section/hostname = "'myserver'"
/files/etc/example.ini/section/port = "80"
整款是树中的一个组成部分,因此调用rm
的塔t部分将删除整个子树。
要匹配标题部分,您需要搜索名为section
的节点,其值(右侧)为header
。 [. = "header"]
命令的一部分是path expression,它针对值为header
的节点进行过滤。
用augeas删除包含标头的大部分文件可能会更好:https://docs.puppet.com/puppet/4.10/resources_augeas.html。这看起来很吸引你吗? –
这是我成功的最后一次尝试,然后我屈服于疯狂,这是augeas :( – jacksonecac
我不特别关心augeas,但它可能是你最好的选择在这里。 –