variable_string_from_augeas

Use Augeas binaries to call Augtool commands and options to get a node label's value.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
prefixThe prefix of the variable name.

This parameter is required.
nameThe variable to define, the full name will be prefix.name.

This parameter is required.
pathThe path to the file and node label.

This parameter is required.
lensThe lens specified by the user in case they want to load a specified lens associated with its file.

This parameter is optional.
fileThe absolute path to the file specified by the user in case they want to load a specified file associated with its lens.

This parameter is optional.

Outcome conditions

You need to replace ${name} with its actual canonified value.

  • ✅ Ok: variable_string_from_augeas_${name}_ok
    • ☑️ Already compliant: variable_string_from_augeas_${name}_kept
    • 🟨 Repaired: variable_string_from_augeas_${name}_repaired
  • ❌ Error: variable_string_from_augeas_${name}_error

Example

method: variable_string_from_augeas
params:
  prefix: VALUE
  name: VALUE
  lens: OPTIONAL_VALUE
  path: VALUE
  file: OPTIONAL_VALUE

Documentation

Augeas is a tool that provides an abstraction layer for all the complexities that turn around editing files with regular expressions. It's a tree based hierarchy tool, that handle system configuration files where you can securely modify your files. To do so you have to provide the path to the node label's value.

This method aims to use augtool to extract a specific information from a configuration file into a rudder variable. If Augeas is not installed on the agent, or if it fails to execute, it will produces an error.

  • variable prefix: target variable prefix
  • variable name: target variable name
  • path: augeas node path, use to describe the location of the target information we want to extract
  • lens: augeas lens to use, optional
  • file: absolute file path to target, optional

Actually there are two ways you can use this method:

  • Either by providing the augeas path to the node's label and let lens and file empty. ** this way augeas will load the common files and lens automatically
  • Or by using a given file path and a specific lens. ** better performances since only one lens is loaded ** support custom lens, support custom paths

This mechanism is the same as in the file_augeas_set method.

With autoload

Let's consider that you want to obtain the value of the ip address of the first line in the /etc/hosts:

(Note that the label and value parameters mentioned are naming examples of variable prefix and variable name, the augeas path /etc/hosts/1/ipaddr represents the ipaddr node label's value (in the augeas mean) in the first line of the file /etc/hosts).

variable_string_from_augeas("label","value","/etc/hosts/1/ipaddr", "", "");

Without autoload

Here we want the same information as in the first example, but we will force the lens to avoid loading unnecessary files.

variable_string_from_augeas("label","value","/etc/hosts/1/ipaddr","Hosts","/etc/hosts");

Difference with file augeas command

This method is very similar to the file augeas command one, both execute an augtool command an dump its output in a rudder variable. But their goal is really different:

  • This one will parse the output of the augeas print that we want to make it directly usable, but will be less flexible in its input.
  • The file augeas command offers much more possibilities to execute an augeas command to modify a file, but the output will be unparsed and most likely unusable as a rudder variable, expect to dump an error or configuration somewhere.