Skip to content

Commit 1f1f7ab

Browse files
committed
Add very basic nested operations example
1 parent 20dc826 commit 1f1f7ab

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

snippets/inventory-functions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example: Inventory Functions
22

3-
Like operations inventories can also be defined using Python functions. This brings incredible flexibility allowing you to pull data from external systems using Python's package ecosystem to generate pyinfra inventories. The `inventory.py` contains a triaival example of this which can be executed like so:
3+
Like operations inventories can also be defined using Python functions. This brings incredible flexibility allowing you to pull data from external systems using Python's package ecosystem to generate pyinfra inventories. The `inventory.py` contains an example of this which can be executed like so:
44

55
```sh
66
pyinfra inventory.make_docker_inventory exec uptime
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Example: Nested Operations
2+
3+
Operations within a `python.call` function are called nested operations. These execute immediately, unlike top-level operations which are collected during the planning phase and executed later. The `nested_ops.py` file contains a very simple example of this.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import requests
2+
from pyinfra.operations import apt, python, server
3+
4+
# Install some service X...
5+
apt.packages(...)
6+
7+
8+
def register_device():
9+
get_idx = server.shell(commands="get identifier from service X")
10+
11+
# Save the service X identifier in some external system
12+
requests.post("", get_idx.stdout)
13+
14+
15+
python.call(function=register_device)

0 commit comments

Comments
 (0)