file_augeas_commands

Use Augeas binaries to execute augtool commands and options directly on the agent.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
variable_prefixThe prefix of the variable name.

This parameter is required.
variable_nameThe variable to define, the full name will be variable_prefix.variable_name.

This parameter is required.
commandsThe augeas command(s).

This parameter is required.
autoloadDeactivate the autoload option if you don't want augeas to load all the files/lens, it's true by default.

Choices:
  • true
  • false

This parameter is optional.

Outcome conditions

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

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

Example

method: file_augeas_commands
params:
  autoload: 'true'
  variable_prefix: VALUE
  commands: VALUE
  variable_name: VALUE

Documentation

Augeas is a tool that provides an abstraction layer for all the complexities that turn around editing files with regular expressions.

This method defines a rudder variable from the output of a augtool command. The method has in total 4 parameters:

  • variable_prefix: target variable prefix
  • variable_name: target variable name
  • commands: augtool script to run
  • autoload: boolean to load or not the common augeas lens, default to true

Augtool provides bunch of other commands and options that you can use in this generic method such as match to print the matches for a specific path expression, span to print position in input file corresponding to tree, retrieve to transform tree into text and save to save all pending changes. If Augeas isn't installed on the agent, it will produces an error.

This method will execute the commands via augtool. The particular thing you may want to do with this method is using it depending on you needs and in two cases.

With autoload

Augeas will accordingly load all files and lenses before executing the commands you have specified since autoload is active.

file_augeas_commands("label","value","print /files/etc/hosts/*/ipaddr[../canonical="server.rudder.local"]","")
# The variable label.value will be defined as such:
${label.value} -> /files/etc/hosts/2/ipaddr = "192.168.2.2"
file_augeas_commands("label","value","ls files/etc/ \n print /files/etc/ssh/sshd_config","true")
# Will define the variable label.value with the list of files availables in /etc and already parsable with augeas,
# followed by the dump of the sshd_config file, parsed by augeas.

Without autoload

The second case is when you deactivate that option which means that you are specifying autoload to false and in this case you have to load manually your files and lenses in the commands parameter by using the set augeas command. Below is a second example where the lens and file are explicitly set:

file_augeas_commands("label","value","set /augeas/load/Sshd/lens "Sshd.lns \n set /augeas/load/Sshd/incl "/etc/ssh/sshd_config" \n load \n print /augeas/load/Sshd \n print /augeas/load/Sshd \n print /files/etc/ssh/sshd_config","false")