config-value-in-file

Example:

# Ensure a key/value pair exists in a file.
- config-value-in-file:
    path: /tmp/app.config
    key: my_key
    value: my_value
    sep: ' = '

Description

Adds a key/value pair to a file.

This looks for a line in a file that starts with the value of the key and sep variables. If it finds it, it'll replace that line with the provided key/value pair, separated by sep.

If your sep value contains whitespaces or special characters, the reg-ex matching probably won't work reliably. In that case you can provide the matching regular expression manually with the match-regex parameter.

If it doesn't find a match, the key/value pair will be appended to the end of the file.

Missing user/group/parent-dir/file will be created if necessary.

Variables

Name Type Default Description

key

string --

The config key. Required

path

string --

The path to the file Required

value

string --

The config value. Required

become

boolean --

Whether to use elevated privileges.

group

string --

The group of the file.

match_regex

string --

An optional matcher (see help).

mode

string --

The permissions of the file.

owner

string --

The owner of the file.

sep

string =

The seperator token.

Examples

Example 1

Ensure a key/value pair exists in a file.

Code
- config-value-in-file:
    path: /tmp/app.config
    key: my_key
    value: my_value
    sep: ' = '

Command-line

frecklecute config-value-in-file --help

Usage: frecklecute config-value-in-file [OPTIONS]

  Adds a key/value pair to a file.

  This looks for a line in a file that starts with the value of the ``key``
  and ``sep`` variables. If it finds it, it'll replace that line with the
  provided ``key``/``value`` pair, separated by ``sep``.

  If your ``sep`` value contains whitespaces or special characters, the reg-
  ex matching probably won't work reliably. In that case you can provide the
  matching regular expression manually with the ``match-regex`` parameter.

  If it doesn't find a match, the key/value pair will be appended to the end
  of the file.

  Missing user/group/parent-dir/file will be created if necessary.

Options:
  --key KEY                  The config key.  [required]
  --path PATH                The path to the file  [required]
  --value VALUE              The config value.  [required]
  --become / --no-become     Whether to use elevated privileges.
  --group GROUP              The group of the file.
  --match-regex MATCH_REGEX  An optional matcher (see help).
  --mode MODE                The permissions of the file.
  --owner USER               The owner of the file.
  --sep SEP                  The seperator token.  [default: =]
  --help                     Show this message and exit.