Date: 2026-05-11
Time: 15:14
FTL modules are in-process Python functions that replace traditional subprocess-based module execution, achieving 250x+ speedups. This page covers the example scripts demonstrating local execution, remote SSH execution, Ansible module compatibility via the module_loading system, and the two primary APIs (direct function calls and the async Executor API).
ftlfile(), ftlcommand(), etc.) for simple use, and the async Executor API (execute, run, executeonhosts) for production patterns.asyncio), enabling concurrent execution across multiple hosts.module_loading system resolves FQCN names (e.g. ansible.builtin.command), builds ZIP bundles with dependencies, and executes them locally or remotely.changed (bool) and content-specific keys (stdout, stderr, etc.). The Executor wraps this in a result object with .success, .changed, .output.LocalHost(name=...) lets you treat local execution with the same host-list pattern used for remote targets.SSHHost manages async SSH connections with async with host: context manager; supports host.run() for raw commands and integration with the Executor via host= parameter.Running examples:
uv run python example_local.py # No setup required
docker-compose up -d # Start test containers for remote
uv run python example_remote.py
docker-compose down
Direct function calls:
from ftl2.ftl_modules import ftl_file, ftl_command, ftl_copy
result = ftl_file(path="/tmp/test.txt", state="touch")
result = ftl_command(cmd="echo hello")
result = ftl_copy(src="/tmp/source.txt", dest="/tmp/dest.txt")
Executor API (async, recommended):
from ftl2.ftl_modules import execute, execute_on_hosts, run, LocalHost
result = await execute("file", {"path": "/tmp/test.txt", "state": "touch"})
result = await run("command", cmd="uptime")
hosts = [LocalHost(name=f"host{i}") for i in range(10)]
results = await execute_on_hosts(hosts, "command", {"cmd": "echo hello"})
SSH remote execution:
from ftl2.ssh import SSHHost
host = SSHHost(hostname="localhost", port=2222, username="testuser",
password="testpass", disable_host_key_checking=True)
async with host:
stdout, stderr, rc = await host.run("uptime")
result = await execute("command", {"cmd": "hostname"}, host=host)
Available modules: file, copy, template, command, shell, uri, geturl, pip — each with a corresponding ftl<name>() function.
ftl2.ssh.SSHHost) — remote execution depends on the async SSH layer; the Executor falls back to Ansible module bundling when running remotely.module_loading system bridges Ansible modules into FTL, resolving fully-qualified collection names to file paths and building deployment bundles.LocalHost and SSHHost are the host abstractions that connect to the broader inventory system (groups, host vars).file, copy, command, template, uri, pip) is central to migration planning.execute/run/executeonhosts) is the recommended API, not direct function calls.executeonhosts enables concurrent execution across a host list — this is the primary scaling pattern.disablehostkey_checking=True is only for test containers — know the security implication.ftlbuiltinmodules and ftlmoduleutils to be installed.file, copy, template, command, shell, uri, get_url, pip..success, .changed, and .output on the Executor result object; raw functions return a dict with changed key.