Python Operations

The Python module allows you to execute Python code within the context of a deploy.

Execute a Python function within a deploy.
  • function: the function to execute
  • args: additional arguments to pass to the function
  • kwargs: additional keyword arguments to pass to the function

Callback functions args passed the state, host, and any args/kwargs passed into the operation directly, eg:

def my_callback(state, host, hello=None):
    command = 'echo hello'
    if hello:
        command = command + ' ' + **hello**

    status, stdout, stderr = host.run_shell_command(command=command, sudo=SUDO)
    assert status is True  # ensure the command executed OK

    if 'hello ' not in '\n'.join(stdout):  # stdout/stderr is a *list* of lines
        raise Exception(
            f'`{command}` problem with callback stdout:{stdout} stderr:{stderr}',
    name='Run my_callback function',