Edit ini files
new
re
all
(for example /etc/sysctl.conf)
Retrieve the whole structure from an ini file and return it as a dictionary.
file_name (str) -- The full path to the ini file.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
names contained in each section
API Example:
import salt.client
with salt.client.get_local_client() as sc:
sc.cmd('target', 'ini.get_ini', [path_to_ini_file])
CLI Example:
salt '*' ini.get_ini /path/to/ini
Get value of a key from a section in an ini file. Returns None if
no matching key was found.
file_name (str) -- The full path to the ini file.
section (str) -- A string value representing the section of the ini that the option is in. If the option is not in a section, leave this empty.
option (str) -- A string value representing the option to search for.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
None if empty or notfound
API Example:
import salt.client
with salt.client.get_local_client() as sc:
sc.cmd('target', 'ini.get_option', [path_to_ini_file, section_name, option])
CLI Example:
salt '*' ini.get_option /path/to/ini section_name option_name
Retrieve a section from an ini file. Returns the section as a dictionary. If the section is not found, an empty dictionary is returned.
file_name (str) -- The full path to the ini file.
section (str) -- A string value representing name of the section to search for.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
section of the ini file. If the section is not found, an empty dictionary is returned
API Example:
import salt.client
with salt.client.get_local_client() as sc:
sc.cmd('target', 'ini.get_section', [path_to_ini_file, section_name])
CLI Example:
salt '*' ini.get_section /path/to/ini section_name
Remove a key/value pair from a section in an ini file. Returns the value of
the removed key, or None if nothing was removed.
file_name (str) -- The full path to the ini file.
section (str) -- A string value representing the section of the ini that the option is in. If the option is not in a section, leave this empty.
option (str) -- A string value representing the option to search for.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
Noneif nothing was removed
API Example:
import salt
sc = salt.client.get_local_client()
sc.cmd('target', 'ini.remove_option', [path_to_ini_file, section_name, option])
CLI Example:
salt '*' ini.remove_option /path/to/ini section_name option_name
Remove a section in an ini file. Returns the removed section as a
dictionary, or None if nothing is removed.
file_name (str) -- The full path to the ini file.
section (str) -- A string value representing the name of the section search for.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
section that was removed or None if nothing was removed
API Example:
import salt.client
with salt.client.get_local_client() as sc:
sc.cmd('target', 'ini.remove_section', [path_to_ini_file, section_name])
CLI Example:
salt '*' ini.remove_section /path/to/ini section_name
Edit an ini file, replacing one or more sections. Returns a dictionary containing the changes made.
file_name (str) -- The full path to the ini file.
sections (dict) -- A dictionary representing the sections to be edited in the ini file.
The keys are the section names and the values are a dictionary
containing the options. If the ini file does not contain sections
the keys and values represent the options. The default is None.
separator (str) --
The character used to separate keys and values. Standard ini files
use the "=" character. The default is =.
New in version 2016.11.0.
encoding (str) --
A string value representing encoding of the target ini file. If
None is passed, it uses the system default which is likely
utf-8. Default is None
New in version 3006.6.
no_spaces (bool) --
A bool value that specifies that the key/value separator will be
wrapped with spaces. This parameter was added to have the ability to
not wrap the separator with spaces. Default is False, which
maintains backwards compatibility.
Warning
This will affect all key/value pairs in the ini file, not just the specific value being set.
New in version 3006.10.
A dictionary representing the changes made to the ini file
API Example:
import salt.client
with salt.client.get_local_client() as sc:
sc.cmd(
'target', 'ini.set_option', ['path_to_ini_file', '{"section_to_change": {"key": "value"}}']
)
CLI Example:
salt '*' ini.set_option /path/to/ini '{section_foo: {key: value}}'