pyinfra.api.operation module

Operations are the core of pyinfra. The @operation wrapper intercepts calls to the function and instead diff against the remote server, outputting commands to the deploy state. This is then run later by pyinfra’s __main__ or the pyinfra.api.operations module module.

class pyinfra.api.operation.OperationMeta(hash, is_change: bool | None)

Bases: object

property changed: bool
did_change() bool
did_error() bool
did_not_change() bool
did_succeed(_raise_if_not_complete=True) bool
property executed: bool
is_complete() bool
set_complete(success: bool, commands: list[Any], combined_output: CommandOutput) None
property stderr: str
property stderr_lines: list[str]
property stdout: str
property stdout_lines: list[str]
property will_change: bool
pyinfra.api.operation.add_op(state: State, op_func, *args, **kwargs)

Prepare & add an operation to pyinfra.state by executing it on all hosts.

Parameters
  • state (pyinfra.api.State obj) – the deploy state to add the operation
  • op_func (to) – the operation function from one of the modules,
  • server.user (ie) –
  • args/kwargs – passed to the operation function
pyinfra.api.operation.attach_args(op_meta, args, kwargs)
pyinfra.api.operation.ensure_shared_op_meta(state: State, op_hash: str, op_order: tuple[int, ...], global_arguments: AllArguments, names: set[str])
pyinfra.api.operation.execute_immediately(state, host, op_hash)
pyinfra.api.operation.generate_operation_name(func, host, kwargs, global_arguments)
pyinfra.api.operation.get_operation_name_from_func(func)
pyinfra.api.operation.operation(is_idempotent: bool = True, idempotent_notice: str | None = None, is_deprecated: bool = False, deprecated_for: str | None = None, _set_in_op: bool = True) Callable[[Callable[[P], Generator]], PyinfraOperation[P]]

Decorator that takes a simple module function and turn it into the internal operation representation that consists of a list of commands + options (sudo, (sudo|su)_user, env).

pyinfra.api.operation.solve_operation_consistency(names, state, host)