config-values-in-file

Example:

# Ensure a few key/value pairs exists in a file.
- config-values-in-file:
    path: /tmp/app.config
    sep: ': '
    config:
      my_key_1: my_value_1
      my_key_2: my_value_2

Description

Adds one or several key/value pairs to a file.

For every pair, 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 and you might not be able to use this.

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

config

dict --

A dict of config key/value pairs. Required

path

string --

The path to the file Required

become

boolean --

Whether to use elevated privileges.

group

string --

The group of the file.

mode

string --

The permissions of the file.

owner

string --

The owner of the file.

sep

string =

The seperator token.

Examples

Example 1

Ensure a few key/value pairs exists in a file.

Code
- config-values-in-file:
    path: /tmp/app.config
    sep: ': '
    config:
      my_key_1: my_value_1
      my_key_2: my_value_2

Command-line

frecklecute config-values-in-file --help

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

  Adds one or several key/value pairs to a file.

  For every pair, 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 and you might not be able to use
  this.

  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:
  --config CONFIG         A dict of config key/value pairs.  [required]
  --path PATH             The path to the file  [required]
  --become / --no-become  Whether to use elevated privileges.
  --group GROUP           The group of the file.
  --mode MODE             The permissions of the file.
  --owner USER            The owner of the file.
  --sep SEP               The seperator token.
  --help                  Show this message and exit.