Overview

Date: 2026-05-11

Time: 15:45

I'll create a summary entry for this dynamic hosts example.

Overview

This example demonstrates FTL2's dynamic host registration and host-scoped proxy syntax — two features that enable provisioning workflows where infrastructure is created and immediately configured in the same script. It shows how to add hosts at runtime with ftl.addhost(), then target them using the cleaner ftl.<host>.module() proxy syntax instead of the older ftl.runon() API.

Usage Patterns

Dynamic host registration — add hosts at runtime rather than defining them in static inventory:


ftl.add_host(
    hostname="web01",
    ansible_host="192.168.1.10",
    groups=["webservers", "production"],
    db_type="postgres",  # arbitrary custom host variables
)

Host-scoped proxy — target hosts or groups with attribute-style access:


await ftl.web01.command(cmd="echo 'target one host'")
await ftl.webservers.command(cmd="echo 'target a group'")
await ftl.localhost.command(cmd="echo 'target localhost'")

FQCN modules with proxy syntax — fully-qualified collection names chain through the proxy:


await ftl.webservers.ansible.builtin.command(cmd="echo 'FQCN works!'")
await ftl.databases.community.postgresql.postgresql_db(name="myapp")

Provisioning workflow — provision, register, configure in sequence:


server = await ftl.community.general.linode_v4(label="web03", ...)
ftl.add_host("web03", ansible_host=server["instance"]["ipv4"][0], groups=["webservers"])
await ftl.web03.apt(name="nginx", state="present")
await ftl.web03.service(name="nginx", state="started")

API and Configuration

| API | Parameters | Purpose |

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

| ftl.addhost() | hostname, ansiblehost, groups=[], **kwargs (custom host vars) | Register a host at runtime |

| ftl.<name>.module() | Module-specific kwargs | Run module on host or group by name |

| ftl.run_on() | target, module, **kwargs | Older explicit targeting (still supported) |

| ftl.hosts | dict-like | Access registered hosts; .keys(), .groups, ['group_name'] |

| ftl.results | list | All results collected during the session |

| ftl.failed | bool | Whether any task failed |

Key Behaviors

Relationships