我正在尝试通过/etc/elasticsearch/elasticsearch.yml
资源修改/设置puppet清单中的augeas
文件,但它无效。有人可以解释我应该指定的lens
文件吗?我是否需要为此安装额外的东西或默认安装中包含所需的镜头?
我正在尝试更改键值对:
key1.key2: value
eg:
cluster.name: cms-es
我的代码:
augeas { "elastic_config":
context => "/files/etc/elasticsearch/elasticsearch.yml",
changes => [
"set 'network.host:' ipaddress_eth0",
"set 'cluster.name:' cms-es",
"set 'node.name:' ec2_hostname",
"set 'bootstrap.mlockall:' true",
],
}
答案 0 :(得分:2)
Augeas目前无法编辑YAML文件,因为无法使用Augeas镜头描述YAML语法。它需要修改Augeas的核心来支持它(以支持一致的标识,这对于这种格式是强制性的。)
答案 1 :(得分:1)
不是最好的解决方案,但如果你只依赖冒号分隔的配置文件,我只是为了这个镜头。
复制&将以下内容粘贴到/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",
]
}