2

I am trying to modify/set /etc/elasticsearch/elasticsearch.yml file in puppet manifest through augeas resource but it is not working. Can someone explain what lens file i should specify ? and Whether i need to install something extra for this or the required lens is included in default installation?

I am trying to change key value pairs like this:

 key1.key2:  value
 eg:


cluster.name: cms-es

My code:

  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",
 ],
}
Ijaz Ahmad
  • 11,198
  • 9
  • 53
  • 73

2 Answers2

3

Augeas cannot currently edit YAML files, because the YAML grammar cannot be described using an Augeas lens. It would require a modification in the core of Augeas to support that (to support consistent identation, which is mandatory for this format).

raphink
  • 3,625
  • 1
  • 28
  • 39
  • I see you were fiddling with the augeas grammar at https://github.com/hercules-team/augeas/commits/master/lenses/yaml.aug before your comment here, so you know that there is a grammar , it is just not very complete. Simple structures do get through, and thus can be edited. – John Vandenberg Nov 05 '17 at 01:55
  • There is a grammar for sure and some parts can be implemented, but it cannot be fully described using Augeas currently (because, as stated, of the requirement for consistent identation). – raphink Nov 07 '17 at 09:33
1

Not the best solution, but if you only rely on colon delimited configuration files, I've a lens just for that.

Copy & paste the following in /usr/share/augeas/lens/colonvars.aug (or use auges module to automate this).

(*
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)*

Here is how you can use it (based on your example):

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",
    ]
}
Alex Simenduev
  • 846
  • 7
  • 6