Overview

Date: 2026-05-11

Time: 15:33

Overview

This file implements FTL2's module proxy system — the magic behind the ftl.modulename() syntax. It intercepts attribute access on the ftl object to dynamically resolve and execute automation modules, supporting both simple names (ftl.file(...)) and fully qualified collection names (ftl.amazon.aws.ec2instance(...)). It also provides HostScopedProxy, which enables host/group-targeted execution via ftl.webservers.service(...). The proxy layer handles module exclusion checks, shadowed (native) module resolution, become/privilege escalation, and audit tracking.

Usage Patterns

Basic module calls — modules are called as async methods on the ftl object:


await ftl.file(path="/tmp/test", state="touch")
await ftl.amazon.aws.ec2_instance(instance_type="t3.micro")

Host-scoped execution — target specific hosts or groups:


await ftl.webservers.service(name="nginx", state="restarted")
await ftl.web01.file(path="/tmp/test", state="touch")

Native shadowed modules — several Ansible modules have FTL2-native replacements built directly into HostScopedProxy:


# Dynamic host provisioning pattern
ftl.add_host("minecraft-9", ansible_host=ip)
await ftl.minecraft_9.wait_for_ssh(timeout=120, delay=10)
await ftl.minecraft_9.copy(src="server.properties", dest="/opt/mc/server.properties")

API and Configuration

| Parameter | Module | Default | Notes |

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

| timeout | waitforssh | 600 | Max seconds to wait |

| delay | waitforssh | 0 | Seconds before first check |

| sleep | waitforssh | 1 | Seconds between retries |

| connecttimeout | waitfor_ssh | 5 | Per-attempt timeout |

| become | copy, template, shell | None | Enable privilege escalation |

| become_user | copy, template, shell | None | Target user for escalation |

| flat | fetch | False | If False, creates dest/hostname/src directory structure |

| creates | shell | None | Skip if path exists (idempotency) |

| removes | shell | None | Skip if path does NOT exist |

| executable | shell | /bin/sh | Shell interpreter |

| backup | copy | False | Create timestamped backup before overwrite |

Become/privilege escalation flows through becomeoverrides dict and per-host become_config. When become is active, copy uses a temp-file-then-sudo-mv pattern instead of direct SFTP writes.

Key Behaviors

Relationships