file_augeas_set

Use augeas commands and options to set a node label's value.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
pathThe path to the file and node label.

This parameter is required.
valueThe value to set.

This parameter is required.
lensLoad a specific lens (optional).

This parameter is optional.
fileLoad a specific file (optional).

This parameter is optional.

Outcome conditions

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

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

Example

method: file_augeas_set
params:
  value: VALUE
  path: VALUE
  lens: OPTIONAL_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 handles system configuration files where you can securely modify your files and to do so you have to provide the path to the node label's value.

Augeas uses lenses which are like sort of modules that are in charge of identifying and converting files into tree and back.

This method uses augtool to force the value of an augeas node's label.

Actually there are two ways to 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, custom paths (for instance to apply the Hosts lens to another file than /etc/hosts)
  • Either by simply providing an augeas path to the node's label

Warning: When you don't specify the file and lens to use, no backup of the file will be made before editing it.

Two uses cases examples:

In the first case, let's suppose that you want to set the value of the ip address of the first line in the /etc/hosts file to 192.168.1.5, to do so you need to provide the augeas path and value parameters.

file_augeas_set("/etc/hosts/1/ipaddr", "192.168.1.5", "", "");

The second case is more efficient, and forces the Hosts lens to parse the /etc/hosts file and set the value for the given path node:

file_augeas_set("/etc/hosts/1/ipaddr", "192.168.1.5", "Hosts", "/etc/hosts");