Beispiel #1
0
from os import path

from pyinfra import local, state
from pyinfra.operations import server


server.shell(
    name='First task operation',
    commands='echo first_task_operation',
)

with state.preserve_loop_order([1, 2]) as loop_items:
    for item in loop_items():
        server.shell(
            name='Task order loop {0}'.format(item),
            commands='echo loop_{0}'.format(item),
        )
        server.shell(
            name='2nd Task order loop {0}'.format(item),
            commands='echo loop_{0}'.format(item),
        )

# Import a file *relative* to this one (./another_task.py)
local.include(path.join('.', 'another_task.py'))
Beispiel #2
0
from pyinfra import state
from pyinfra.modules import server

SUDO = True

items = ['a', 'b', 'c']

# This loop will be executed as:
# > item: a
# > item: b
# > item: c
# > end item: a
# > end item: b
# > end item: c
for item in items:
    server.shell({'item: {0}'.format(item)}, 'hi')
    server.shell({'end item: {0}'.format(item)}, 'hi')

# This loop will be executed as:
# > item: a
# > end item: a
# > item: b
# > end item: b
# > item: c
# > end item: c
with state.preserve_loop_order(items) as loop_items:
    for item in loop_items():
        server.shell({'item: {0}'.format(item)}, 'hi')
        server.shell({'end item: {0}'.format(item)}, 'hi')