Overview

Date: 2026-05-11

Time: 15:42

Overview

This is an example/demo script that shows how to execute Ansible builtin modules (like ping, command, stat, file, tempfile) through FTL2's module_loading system. It demonstrates the subprocess-based Ansible module execution path, bundle building for remote execution, and includes a performance comparison between FTL2-native modules and Ansible modules. It serves as both documentation and a runnable tutorial for users migrating from or integrating with Ansible.

Usage Patterns

Run directly as a script:


python examples/ansible_builtin_modules.py

Key execution patterns demonstrated:


# Execute a module by FQCN with parameters
from ftl2.module_loading.executor import execute_local_fqcn
result = execute_local_fqcn("ansible.builtin.command", {"_raw_params": "echo hello"})
print(result.success, result.output.get("stdout"))

# Resolve FQCN to filesystem path
from ftl2.module_loading.fqcn import resolve_fqcn
path = resolve_fqcn("ansible.builtin.command")

# Build a bundle for remote execution
from ftl2.module_loading.bundle import build_bundle_from_fqcn
bundle = build_bundle_from_fqcn("ansible.builtin.command")

# Execute a bundle locally
from ftl2.module_loading.executor import execute_bundle_local
result = execute_bundle_local(bundle, {"_raw_params": "echo hello"})

# Execute remotely via SSH
from ftl2.module_loading.executor import execute_remote_with_staging
result = await execute_remote_with_staging(host, bundle, {"_raw_params": "hostname"})

API and Configuration

Dependencies: Requires ftlbuiltinmodules and ftlmoduleutils packages installed (pip install -e ../ftlbuiltinmodules and pip install -e ../ftlmoduleutils).

Module parameters follow Ansible conventions — each module takes a dict of parameters (e.g., {"path": "/etc/hosts"} for stat, {"rawparams": "echo hi"} for command, {"state": "touch", "path": "..."} for file).

Remote execution requires a Docker container with SSH access, configured via:


SSH_CONFIG = {
    "hostname": "localhost", "port": 2222,
    "username": "testuser", "password": "testpass",
    "disable_host_key_checking": True,
}

ExecutionResult fields: success (bool), output (dict), error (str|None), changed (bool).

Key Behaviors

Relationships