Local automation execution
Local automation execution turns a task and its project inputs into a controlled process on the local runner host. It prepares the repository, inventory, credentials, variables, and task-specific files before it starts Ansible, Terraform, or a shell command, then removes temporary resources after the process ends.
Execution lifecycle
The local executor owns one task run from preparation through cleanup. It separates setup from process execution so the same prepared inputs can support both normal local runs and other execution boundaries. The parent page, Automation execution, describes how this lifecycle fits into task dispatch; Task orchestration and state covers the state and log owners; Runner-backed execution covers the remote alternative.
Preparation sequence
Preparation resolves all inputs that the application process needs. The executor installs host mappings and credentials first, makes the repository and inventory available, prepares application requirements, and then builds the final arguments and environment.
The run follows this high-level sequence:
flowchart TD
A[Task received by local executor] --> B[Install host mappings and credentials]
B --> C[Prepare repository and inventory]
C --> D[Prepare application requirements]
D --> E[Build variables arguments and inputs]
E --> F[Start local application process]
F --> G[Stream logs and accept prompts]
G --> H[Collect successful workflow outputs]
H --> I[Remove temporary files and credentials]
The executor marks the task as running during preparation. A task that fails before process start returns the preparation error, while a task that reaches execution uses the application adapter to report output and status through the task logger.
References: services/…/local_executor.go• L817-855 services/…/local_executor.go• L960-1140 services/…/local_executor.go• L1143-1156
Task inputs
Local execution combines project content with run-time task data. The repository and inventory provide the files that automation acts on, while environment values, survey answers, access keys, and task parameters shape what the process does.
Repository workspace
The repository workspace is the task's local source of playbooks, scripts, modules, and other automation content. For a remote repository, the executor updates and checks out the effective branch or commit before it starts the application. A local repository is checked for presence instead of being cloned.
The application runs from a repository-based directory. An Ansible working directory may narrow that location, but it must remain inside the repository. Parallel tasks can share a checkout, so Git update and checkout operations are serialized for that shared directory.
References: services/…/local_executor.go• L688-710 services/…/local_executor.go• L1180-1193 services/…/local_executor.go• L1300-1375 db_lib/AnsiblePlaybook.go• L25-68
Inventory sources
An inventory defines the hosts and connection data that an Ansible task can target. The executor supports inventory content written for the task and inventory files supplied by a repository. Static content is written to a task-specific temporary file; a repository inventory is made available from its local or cloned repository location.
Inventory access keys are installed before execution. The executor passes the matching user, become, SSH, and host-mapping settings to Ansible so host access uses the credentials selected by the project. Inventory repositories use the same host mappings as the main repository and are protected from conflicting parallel Git operations.
References: services/…/local_executor_inventory.go• L14-36 services/…/local_executor_inventory.go• L43-107 services/…/local_executor.go• L488-545 services/…/local_executor.go• L1436-1455
Variables and secrets
The executor builds one task input model from environment data, survey answers, variable-group values, task details, and workflow context. Survey values targeted at the process environment become environment entries. Other values become application variables, so each value reaches the task through one intended channel.
For Ansible, non-secret variables are passed through a YAML file. Secret variables are separated into a second file encrypted with a one-time Ansible Vault password. The password is supplied only as process input. Temporary variable files are removed during cleanup.
The same merged values serve related task types through their native input forms. Shell tasks receive command arguments and environment entries. Terraform-family tasks receive stage-specific variable arguments. Task identity variables let a running process identify the project, task, and workflow run that started it.
References: services/…/local_executor.go• L182-245 services/…/local_executor.go• L268-327 services/…/local_executor.go• L364-484 services/…/local_executor.go• L1089-1114 services/…/extra_vars_file.go• L134-152 services/…/extra_vars_file.go• L153-226
Access key material
Access keys are temporary run resources rather than permanent files in the task workspace. The executor installs them when a task needs repository, inventory, become, vault, or host-mapping access. It removes the installed material after the run, including when preparation stops part-way through.
Project host mappings also apply to tools started by the task. This lets nested Git operations such as Ansible Galaxy downloads or playbook actions use the same mapped credentials as the executor's own repository operations.
References: services/…/local_executor.go• L974-982 services/…/local_executor.go• L1378-1408 services/…/local_executor.go• L1410-1455 services/…/local_executor_inventory.go• L137-159 db_lib/AnsibleApp.go• L111-139
Application execution
The executor selects an application adapter from the template's task type. Each adapter receives prepared arguments, environment values, prompt answers, parameters, and a stop signal, then starts the matching local command from the prepared working directory.
Ansible process
Ansible execution uses the prepared inventory and playbook paths as its command inputs. The executor adds permitted task controls such as limits, tags, check mode, diff mode, vault sources, and extra variables. It passes prompt answers through the process terminal for SSH, become, and vault requests.
Ansible output is attached to the task logger while the process runs. Workflow tasks can also expose an output file and callback path through the process environment; successful output is collected only after the application finishes successfully.
References: services/…/local_executor.go• L488-685 db_lib/AnsibleApp.go• L73-109 db_lib/AnsiblePlaybook.go• L82-142 services/…/local_executor.go• L864-957
Related task types
Shell tasks run a configured command from the repository workspace and receive their extra values as command arguments or environment entries. Terraform, OpenTofu, and Terragrunt tasks use staged arguments, prepare their working state, and run their own initialization, workspace, plan, and apply phases through the same local executor boundary.
The shared boundary keeps repository setup, credentials, cancellation, logging, and cleanup consistent. The application adapter owns the task tool's process shape and any tool-specific preparation.
References: db_lib/AppFactory.go• L8-37 db_lib/LocalApp.go• L71-92 db_lib/ShellApp.go• L43-119 db_lib/TerraformApp.go• L267-307 db_lib/TerraformApp.go• L359-428
Cancellation and cleanup
Cancellation travels from the executor to the child process through a stop signal. A cancellation before process start prevents the command from starting; a cancellation during execution stops the process and still runs cleanup. The executor accepts only one run, which prevents reuse of prepared state and temporary resources.
Cleanup removes installed keys, generated inventories, extra-variable files, workflow output capture resources, and application-specific working files. This cleanup is safe after partial preparation, so an early failure does not require a separate recovery path.
References: services/…/local_executor.go• L95-119 services/…/local_executor.go• L817-855 services/…/local_executor.go• L1143-1156 db_lib/AnsiblePlaybook.go• L92-137 db_lib/command.go• L9-58
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to inventory paths or repository checkout rules must preserve the distinction between task-scoped static files and shared repository inventories.
- Changes to variable targets must keep environment-target survey values out of extra variables so one answer is not passed twice.
- Changes to Ansible secret handling must preserve the split between the open variable file and the Vault-encrypted file. The Vault prompt name and input answer must remain aligned.
- Changes to application adapters must keep the prepared argument map, environment, prompt inputs, stop signal, and cleanup contract consistent with db_lib/LocalApp.go.
- Changes to shared repository use must preserve serialized Git operations for parallel tasks.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Repository or inventory access fails during preparation | The application process does not start | Preparation returns the access or checkout error before command construction completes |
| Environment, survey, or argument data is invalid | The task stops before execution with no valid input model | JSON and task parameter parsing must succeed during preparation |
| An Ansible working directory points outside the repository | The task cannot run from that directory | Working-directory resolution rejects paths outside the repository root |
| A secret extra variable cannot be written or encrypted | Ansible does not start with incomplete secret input | Secret file creation fails the run and cleanup removes partial files |
| A task is canceled before or during process start | The process is skipped or stopped | The stop signal is checked before start and watched during execution |
| Temporary credentials or files remain after a run | Later tasks may see stale material or sensitive data | The single cleanup path destroys keys, files, and app resources |
Key files
| File | Why to read it |
|---|---|
| services/…/local_executor.go | Defines the local run lifecycle and combines repositories, inventories, variables, credentials, arguments, and cleanup. |
| services/…/local_executor_inventory.go | Explains inventory file placement, inventory repository preparation, and inventory credential cleanup. |
| services/…/extra_vars_file.go | Defines how Ansible variables are split, protected, written, and removed. |
| services/…/local_executor_provider.go | Shows how each local task receives its application adapter, key installer, repository lock, and workflow output collector. |
| db_lib/LocalApp.go | Defines the common preparation and execution contract for local application types. |
| db_lib/AnsiblePlaybook.go | Shows how Ansible starts in the repository workspace, receives prompt input, streams output, and handles cancellation. |
| db_lib/AppFactory.go | Maps template application types to Ansible, Terraform-family, or shell execution behavior. |