cdist-type__key_value7
Change property values in files
Overview
This cdist type allows you to change values in a key value based config file.
Required parameters
|
The file to operate on. |
|---|---|
|
The delimiter which separates the key from the value. |
Optional parameters
state-
present or absent, defaults to present. If present, sets the key to value, if absent, removes the key from the file.
key-
The key to change. Defaults to object_id.
value-
The value for the key. Optional if state=absent, required otherwise.
comment-
If supplied, the value will be inserted before the line with the key, but only if the key or value must be changed. You need to ensure yourself that the line is prefixed with the correct comment sign. (for example # or ; or wathever ..)
onchange-
The code to run if the key or value changes (i.e. is inserted, removed or replaced).
Boolean parameters
exact_delimiter-
If supplied, treat additional whitespaces between key, delimiter and value as wrong value.
Messages
|
Removed existing key and value |
|---|---|
|
Added key and value |
|
Changed value of existing key |
|
A new line was inserted in a new file |
Examples
# Set the maximum system user id __key_value SYS_UID_MAX --file /etc/login.defs --value 666 --delimiter ' ' # Same with fancy id __key_value my-fancy-id --file /etc/login.defs --key SYS_UID_MAX --value 666 \ --delimiter ' ' # Enable packet forwarding __key_value net.ipv4.ip_forward --file /etc/sysctl.conf --value 1 \ --delimiter ' = ' --comment '# my linux kernel should act as a router' # Remove existing key/value __key_value LEGACY_KEY --file /etc/somefile --state absent --delimiter '='
More information
This type try to handle as many values as possible, so it doesn't use regexes. So you need to exactly specify the key and delimiter. Delimiter can be of any length.
Copying
Copyright (C) 2011 Steven Armstrong. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Releases
5 releases since Debian 9 (Stretch); the text changed 4 times.