Overview

Date: 2026-05-11

Time: 15:17

Overview

The FTL2 automation context manager provides a Pythonic, async interface for writing automation scripts. Using async with automation() as ftl:, users access modules as attributes (ftl.file(...), ftl.copy(...)), manage inventory and secrets, run in check mode, handle errors, and control output — all without boilerplate. The interface is designed to be AI-friendly and runs FTL native modules in-process at 250x the speed of subprocess-based execution.

Key Concepts

Commands and Syntax

Basic script structure:


from ftl2 import automation

async with automation() as ftl:
    await ftl.file(path="/tmp/test", state="directory")
    await ftl.copy(src="config.yml", dest="/etc/app/config.yml")
    await ftl.command(cmd="systemctl restart myapp")

Running examples: uv run python examplephase1basic.py

Inventory from YAML: automation(inventory="hosts.yml")

Inventory from dict: automation(inventory={"group": {"hosts": {"host01": {"ansible_host": "1.2.3.4"}}}})

Host access API:

Secrets: automation(secrets=["AWSACCESSKEYID", "APITOKEN"]) then ftl.secrets["AWSACCESSKEYID"], .get("KEY", "default"), .loadedkeys()

Check mode: automation(check_mode=True)

Fail fast with exception handling:


from ftl2.automation import AutomationError
try:
    async with automation(fail_fast=True) as ftl:
        await ftl.file(path="/nonexistent", state="touch")
except AutomationError as e:
    print(f"Module: {e.result.module}")

FQCN: await ftl.amazon.aws.ec2instance(name="my-instance", instancetype="t3.micro")

Relationships

Exam-Relevant Points