不是最好的解决方案,但如果你只依赖冒号分隔的配置文件,我有一个镜头就是为了这个。
复制并粘贴以下内容/usr/share/augeas/lens/colonvars.aug
(或使用auges模块自动执行此操作)。
(*
Module: Colonvars
Parses a simple colon (:) delimited files
Author: Alex Simenduev <shamil.si@gmail.com>
About: Usage Example
(start code)
augtool> set /augeas/load/Colonvars/lens "Colonvars.lns"
augtool> set /augeas/load/Colonvars/incl "/etc/elasticsearch/elasticsearch.yml"
augtool> load
augtool> get /files/etc/elasticsearch/elasticsearch.yml/cluster.name
/files/etc/elasticsearch/elasticsearch.yml/cluster.name = elk
augtool> set /files/etc/elasticsearch/elasticsearch.yml/node.name elk-node-0
augtool> save
Saved 1 file(s)
$ grep node.name /etc/elasticsearch/elasticsearch.yml
node.name: elk-node-0
(end code)
About: License
This file is licensed under the LGPL v2+, like the rest of Augeas.
*)
module Colonvars =
let colon = del /[ \t]*:[ \t]*/ ": "
let entry = Build.key_value_line Rx.word colon (store Rx.space_in)
let lns = (Util.empty | Util.comment | entry)*
以下是您如何使用它(基于您的示例):
augeas { "elastic_config":
incl => "/etc/elasticsearch/elasticsearch.yml",
lens => "Colonvars.lns",
changes => [
"set network.host ipaddress_eth0",
"set cluster.name cms-es",
"set node.name ec2_hostname",
"set bootstrap.mlockall true",
]
}