mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
parent
80a99c4cc5
commit
db0b0cefb8
@ -1411,45 +1411,62 @@ def line(path, content, match=None, mode=None, location=None,
|
||||
'''
|
||||
.. versionadded:: 2015.8.0
|
||||
|
||||
Edit a line in the configuration file.
|
||||
Edit a line in the configuration file. The ``path`` and ``content``
|
||||
arguments are required, as well as passing in one of the ``mode``
|
||||
options.
|
||||
|
||||
:param path:
|
||||
.. note::
|
||||
|
||||
If ``mode=insert`` is used, at least one of the following
|
||||
options must also be defined: ``location``, ``before``, or
|
||||
``after``. If ``location`` is used, it takes precedence
|
||||
over the other two options.
|
||||
|
||||
path
|
||||
Filesystem path to the file to be edited.
|
||||
|
||||
:param content:
|
||||
content
|
||||
Content of the line.
|
||||
|
||||
:param match:
|
||||
match
|
||||
Match the target line for an action by
|
||||
a fragment of a string or regular expression.
|
||||
|
||||
:param mode:
|
||||
:Ensure:
|
||||
If line does not exist, it will be added.
|
||||
If neither ``before`` nor ``after`` are provided, and ``match``
|
||||
is also ``None``, match becomes the ``content`` value.
|
||||
|
||||
:Replace:
|
||||
If line already exist, it will be replaced.
|
||||
mode
|
||||
Defines how to edit a line. One of the following options is
|
||||
required:
|
||||
|
||||
:Delete:
|
||||
- ensure
|
||||
If line does not exist, it will be added. This is based on the
|
||||
``content`` argument.
|
||||
- replace
|
||||
If line already exists, it will be replaced.
|
||||
- delete
|
||||
Delete the line, once found.
|
||||
|
||||
:Insert:
|
||||
- insert
|
||||
Insert a line.
|
||||
|
||||
:param location:
|
||||
:start:
|
||||
Place the content at the beginning of the file.
|
||||
location
|
||||
Defines where to place content in the line. Note this option is only
|
||||
used when ``mode=insert``. If location a location is passed in, it
|
||||
takes precedence over both the ``before`` and ``after`` kwargs. Valid
|
||||
locations are:
|
||||
|
||||
:end:
|
||||
- start
|
||||
Place the content at the beginning of the file.
|
||||
- end
|
||||
Place the content at the end of the file.
|
||||
|
||||
:param before:
|
||||
before
|
||||
Regular expression or an exact case-sensitive fragment of the string.
|
||||
|
||||
:param after:
|
||||
after
|
||||
Regular expression or an exact case-sensitive fragment of the string.
|
||||
|
||||
:param show_changes:
|
||||
show_changes
|
||||
Output a unified diff of the old file and the new file.
|
||||
If ``False`` return a boolean if any changes were made.
|
||||
Default is ``True``
|
||||
@ -1458,31 +1475,33 @@ def line(path, content, match=None, mode=None, location=None,
|
||||
Using this option will store two copies of the file in-memory
|
||||
(the original version and the edited version) in order to generate the diff.
|
||||
|
||||
:param backup:
|
||||
backup
|
||||
Create a backup of the original file with the extension:
|
||||
"Year-Month-Day-Hour-Minutes-Seconds".
|
||||
|
||||
:param quiet:
|
||||
quiet
|
||||
Do not raise any exceptions. E.g. ignore the fact that the file that is
|
||||
tried to be edited does not exist and nothing really happened.
|
||||
|
||||
:param indent:
|
||||
indent
|
||||
Keep indentation with the previous line.
|
||||
|
||||
If an equal sign (``=``) appears in an argument to a Salt command, it is
|
||||
interpreted as a keyword argument in the format of ``key=val``. That
|
||||
processing can be bypassed in order to pass an equal sign through to the
|
||||
remote shell command by manually specifying the kwarg:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' file.line /path/to/file content="CREATEMAIL_SPOOL=no" match="CREATE_MAIL_SPOOL=yes" mode="replace"
|
||||
|
||||
CLI Examples:
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' file.line /etc/nsswitch.conf "networks:\tfiles dns" after="hosts:.*?" mode='ensure'
|
||||
|
||||
.. note::
|
||||
|
||||
If an equal sign (``=``) appears in an argument to a Salt command, it is
|
||||
interpreted as a keyword argument in the format of ``key=val``. That
|
||||
processing can be bypassed in order to pass an equal sign through to the
|
||||
remote shell command by manually specifying the kwarg:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' file.line /path/to/file content="CREATEMAIL_SPOOL=no" match="CREATE_MAIL_SPOOL=yes" mode="replace"
|
||||
'''
|
||||
path = os.path.realpath(os.path.expanduser(path))
|
||||
if not os.path.isfile(path):
|
||||
|
Loading…
Reference in New Issue
Block a user