You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/using-operations.rst
+15-44Lines changed: 15 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ See :doc:`facts` for a full list of available facts and arguments.
109
109
Only use immutable facts in deploy code (installed OS, Arch, etc) unless you are absolutely sure they will not change. See: `using host facts <deploy-process.html#using-host-facts>`_.
110
110
111
111
Fact Errors
112
-
~~~~~~~~~~~
112
+
^^^^^^^^^^^
113
113
114
114
When facts fail due to an error the host will be marked as failed just as it would when an operation fails. This can be avoided by passing the ``_ignore_errors`` argument:
115
115
@@ -141,29 +141,23 @@ Like ``host``, there is an ``inventory`` object that can be used to access the e
141
141
)
142
142
143
143
144
-
Operation Changes & Output
145
-
--------------------------
144
+
Change Detection
145
+
----------------
146
146
147
147
All operations return an operation meta object which provides information about the changes the operation *will* execute. This can be used to control other operations via the ``_if`` argument:
148
148
149
149
.. code:: python
150
150
151
151
from pyinfra.operations import server
152
152
153
-
create_user = server.user(
154
-
name="Create user myuser",
155
-
user="myuser",
156
-
)
157
-
158
-
create_otheruser = server.user(
159
-
name="Create user otheruser",
160
-
user="otheruser",
161
-
)
153
+
create_user = server.user(...)
154
+
create_otheruser = server.user(...)
162
155
163
156
server.shell(
164
157
name="Bootstrap myuser",
165
158
commands=["..."],
166
-
_if=create_user.did_change,
159
+
# Only execute this operation if the first user create executed any changes
pyinfra doesn't immediately execute operations, meaning output is not available right away. It is possible to access this output at runtime by providing a callback function using the :ref:`operations:python.call` operation.
183
+
pyinfra doesn't immediately execute operations, meaning output is not available right away. It is possible to access this output at runtime by providing a callback function using the :ref:`operations:python.call` operation. Callback functions may also call other operations which will be immediately executed. Why/how this works `is described here <deploy-process.html#how-pyinfra-detects-changes-orders-operations>`_.
190
184
191
185
.. code:: python
192
186
@@ -218,40 +212,17 @@ There is also the possibility to use pyinfra's logging functionality which may b
Nested operations are called during the execution phase within a callback function passed into a :ref:`operations:python.call`. Calling a nested operation immediately executes it on the target machine. This is useful in complex scenarios where one operation output is required in another.
232
-
233
-
Because nested operations are executed immediately, the output is always available right away:
234
-
235
-
.. code:: python
236
-
237
-
from pyinfra import logger
238
-
from pyinfra.operations import python, server
239
-
240
-
defcallback():
241
-
result = server.shell(
242
-
commands=["echo output"],
243
-
)
244
-
245
-
logger.info(f"Got result: {result.stdout}")
246
-
247
-
python.call(
248
-
name="Execute callback function",
249
-
function=callback,
250
-
)
251
-
252
-
253
-
Include Multiple Files
254
-
----------------------
224
+
Include Files
225
+
-------------
255
226
256
227
Including files can be used to break out operations across multiple files. Files can be included using ``local.include``.
0 commit comments