file_ensure_key_value_parameter_in_list
Ensure that one parameter exists in a list of parameters, on one single line, in the right hand side of a key->values line.
⚙️ Compatible targets: Linux
⚠️ Deprecated: This method is deprecated and should not be used.
Parameters
Name | Documentation |
---|---|
path | File name to edit (absolute path on the target node). This parameter is required. |
key | Full key name. This parameter is required. |
key_value_separator | character used to separate key and value in a key-value line. This parameter can contain only whitespaces. This parameter is required. |
parameter | String representing the sub-value to ensure is present in the list of parameters that form the value part of that line. This parameter is required. |
parameter_separator | Character used to separate parameters in the list. This parameter can contain only whitespaces. This parameter is required. |
leading_char_separator | leading character of the parameters. This parameter is optional. |
closing_char_separator | closing character of the parameters. This parameter is optional. |
Outcome conditions
You need to replace ${path}
with its actual canonified value.
- ✅ Ok:
file_ensure_key_value_parameter_in_list_${path}_ok
- ☑️ Already compliant:
file_ensure_key_value_parameter_in_list_${path}_kept
- 🟨 Repaired:
file_ensure_key_value_parameter_in_list_${path}_repaired
- ☑️ Already compliant:
- ❌ Error:
file_ensure_key_value_parameter_in_list_${path}_error
Example
method: file_ensure_key_value_parameter_in_list
params:
parameter_separator: VALUE
path: VALUE
key_value_separator: VALUE
parameter: VALUE
key: VALUE
closing_char_separator: OPTIONAL_VALUE
leading_char_separator: OPTIONAL_VALUE
Documentation
Edit the file, and ensure it contains the defined parameter in the list of values on the right hand side of a key->values line. If the parameter is not there, it will be added at the end, separated by parameter_separator. Optionally, you can define leading and closing character to enclose the parameters If the key does not exist in the file, it will be added in the file, along with the parameter
Example
If you have an initial file (/etc/default/grub
) containing
GRUB_CMDLINE_XEN="dom0_mem=16G"
To add parameter dom0_max_vcpus=32
in the right hand side of the line, you'll need the following policy
file_ensure_key_value_parameter_in_list("/etc/default/grub", "GRUB_CMDLINE", "=", "dom0_max_vcpus=32", " ", "\"", "\"");