mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
fixes saltstack/salt#65222 document using slots for contents via function call in file state modules
This commit is contained in:
parent
f2121e5ade
commit
2304b355b1
2 changed files with 78 additions and 0 deletions
|
@ -68,3 +68,71 @@ Here is an example of result parsing and appending:
|
|||
file.copy:
|
||||
- name: __slot__:salt:user.info(someuser).home ~ /subdirectory
|
||||
- source: salt://somefile
|
||||
|
||||
Execution Module Returns as File Contents or Data
|
||||
-------------------------------------------------
|
||||
|
||||
The following examples demonstrate how to use execution module returns as file
|
||||
contents or data in Salt states. These examples show how to incorporate the
|
||||
output of execution functions into file contents or data in the `file.managed`
|
||||
and `file.serialize` states.
|
||||
|
||||
Content from Execution Modules
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You can use the results of execution modules directly as file contents in Salt
|
||||
states. This can be useful for dynamically generating file content based on the
|
||||
output of execution functions.
|
||||
|
||||
**Example 1: Using `test.echo` Output as File Content**
|
||||
|
||||
The following Salt state uses the `test.echo` execution function to generate the
|
||||
text "hello world." This output is then used as the content of the file
|
||||
`/tmp/things.txt`:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
content-from-slots:
|
||||
file.managed:
|
||||
- name: /tmp/things.txt
|
||||
- contents: __slot__:salt:test.echo("hello world")
|
||||
|
||||
**Example 2: Using Multiple `test.echo` Outputs as Appended Content**
|
||||
|
||||
In this example, two `test.echo` execution functions are used to generate
|
||||
"hello" and "world" strings. These strings are then joined by newline characters
|
||||
and then used as the content of the file `/tmp/things.txt`:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
content-from-multiple-slots:
|
||||
file.managed:
|
||||
- name: /tmp/things.txt
|
||||
- contents:
|
||||
- __slot__:salt:test.echo("hello")
|
||||
- __slot__:salt:test.echo("world")
|
||||
|
||||
Serializing Data from Execution Modules
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You can also serialize data obtained from execution modules and write it to
|
||||
files using Salt states. This allows you to capture and store structured data
|
||||
for later use.
|
||||
|
||||
**Example: Serializing `grains.items()` Output to JSON**
|
||||
|
||||
In this example, the `grains.items()` execution function retrieves system
|
||||
information. The obtained data is then serialized into JSON format and saved to
|
||||
the file `/tmp/grains.json`:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
serialize-dataset-from-slots:
|
||||
file.serialize:
|
||||
- name: /tmp/grains.json
|
||||
- serializer: json
|
||||
- dataset: __slot__:salt:grains.items()
|
||||
|
||||
These examples showcase how to leverage Salt's flexibility to use execution
|
||||
module returns as file contents or serialized data in your Salt states, allowing
|
||||
for dynamic and customized configurations.
|
||||
|
|
|
@ -2668,6 +2668,11 @@ def managed(
|
|||
be used instead. However, this will not work for binary files in
|
||||
Salt releases before 2015.8.4.
|
||||
|
||||
.. note:: For information on using Salt Slots and how to incorporate
|
||||
execution module returns into file content or data, refer to the
|
||||
`Salt Slots documentation
|
||||
<https://docs.saltproject.io/en/latest/topics/slots/index.html>`_.
|
||||
|
||||
contents_grains
|
||||
.. versionadded:: 2014.7.0
|
||||
|
||||
|
@ -7881,6 +7886,11 @@ def serialize(
|
|||
|
||||
.. versionadded:: 2015.8.0
|
||||
|
||||
.. note:: For information on using Salt Slots and how to incorporate
|
||||
execution module returns into file content or data, refer to the
|
||||
`Salt Slots documentation
|
||||
<https://docs.saltproject.io/en/latest/topics/slots/index.html>`_.
|
||||
|
||||
serializer (or formatter)
|
||||
Write the data as this format. See the list of
|
||||
:ref:`all-salt.serializers` for supported output formats.
|
||||
|
|
Loading…
Add table
Reference in a new issue