Overview

Date: 2026-05-11

Time: 15:46

Overview

This is a Phase 1 example script demonstrating FTL2's core automation context manager interface. It shows how to use the automation() async context manager from ftl2 to run modules (file, copy, command) with a clean ftl.module_name() syntax, and covers module restriction, verbose mode, and result tracking.

Usage Patterns

The primary pattern is an async context manager that exposes modules as direct method calls:


from ftl2 import automation

async with automation() as ftl:
    result = await ftl.file(path="/tmp/test.txt", state="touch")
    result = await ftl.command(cmd="echo hello")
    result = await ftl.copy(src="/tmp/a.txt", dest="/tmp/b.txt")

Module results are dicts with keys like changed, stdout. Results are also tracked on ftl.results as objects with .success, .changed, and .module attributes.

Restricting available modules:


async with automation(modules=["file", "copy"]) as ftl:
    # ftl.command() would raise AttributeError

Verbose/debug mode:


async with automation(verbose=True) as ftl:
    ...

API and Configuration

| Parameter | Type | Description |

|-----------|------|-------------|

| modules | list[str] | Restrict which modules are available (default: all). Unlisted modules raise AttributeError. |

| verbose | bool | Enable verbose output for debugging. |

Module call signatures shown:

Result dict keys: changed, stdout (for command).

Tracked result attributes: .success, .changed, .module.

Key Behaviors

Relationships