Search code examples
puppetpuppet-enterpriseaugeas

Modifying yml file in augeas


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",
 ],
}

Solution

  • 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 <[email protected]>
    
    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",
        ]
    }