Introducing a new way to review your PRs.

Read the announcement

semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform/OpenTofu/Terragrunt, PowerShell and other DevOps tools.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / repository-and-automation-content

Repository and automation content

Repositories provide the source content for project tasks. The system selects a Git client, keeps a safe checkout for the requested branch or revision, chooses an application for that content, and prepares the tools and secrets needed to run it.

Repository lifecycle

The repository lifecycle turns a project repository record into usable task content. A repository can point to a local path or to a remote Git source, and remote access uses the repository access key plus the project's host mappings.

Remote operations follow this path:

flowchart LR
    A[Repository and branch] --> B[Select Git client]
    B --> C[Install access and host mappings]
    C --> D{Checkout is usable?}
    D -->|No| E[Clone]
    D -->|Yes| F[Pull when safe]
    F -->|Pull fails| E
    E --> G[Checkout requested revision]
    F --> G
    G --> H[Run task from checkout]

The system checks whether a checkout is a real Git repository before it reuses it. It removes broken or stale content and clones again when an update cannot safely continue. Retry settings absorb short Git service outages before the task fails. Each repository and branch has an isolated checkout name; a monorepo can instead share one branch checkout across its templates. db_lib/GitRepository.go• L74-130, db/Repository.go• L38-121, services/…/local_executor.go• L1300-1375

Repository management also supports branch lookup and content browsing. Remote browsing uses a shallow scratch checkout for the selected branch, while local repositories are read from their configured path. The API does not allow repository deletion while a template still uses it, and a changed remote URL clears the old checkout cache. api/…/repository.go• L41-213, api/…/repository.go• L237-371

Git client selection

Git operations share one client contract so the rest of the system does not depend on how Git runs. Configuration selects either the in-process Go client or the command-line Git client, with command-line Git as the fallback. The two clients support the same high-level work: clone, pull, checkout, branch lookup, and commit lookup. db_lib/GitClientFactory.go• L5-26, db_lib/GitRepository.go• L35-44

The command-line client supports project host mappings through generated Git settings. The Go client does not support those mappings and reports a clear configuration error instead of silently using the wrong credential. This makes client selection part of the access contract for projects that use host mappings. db_lib/CmdGitClient.go• L23-91, db_lib/GoGitClient.go• L42-87, db_lib/HostConfigLoader.go• L15-48

References: db_lib/GitClientFactory.go• L5-26 db_lib/CmdGitClient.go• L23-91 db_lib/GoGitClient.go• L42-87

Application factories

An application factory maps a template's application type to the runner that can prepare and execute its content. This keeps task lifecycle work common while giving Ansible, Terraform-family tools, and configured shell tools the behavior they need. db_lib/AppFactory.go• L8-37, db_lib/LocalApp.go• L71-92

Content typeMain purposeEntry content
AnsibleRun a playbook against an inventoryYAML playbook
Terraform, OpenTofu, or TerragruntInitialize and manage infrastructure stateRepository directory
Configured shell or script applicationRun a configured command against repository contentApplication-specific file or directory

Before the application runs, the executor prepares its repository, inventory, environment, access keys, and application requirements. After the run, it clears temporary files and installed secrets. services/…/local_executor.go• L960-1141, services/…/local_executor.go• L1143-1155

Ansible preparation

Ansible preparation installs roles and collections only when the repository contains the matching requirements files or when the template does not skip that step. The system caches a content hash for each requirements file so unchanged dependencies do not need another install. Repository credentials are passed to ansible-galaxy without placing the secret in the task command line. db_lib/AnsibleApp.go• L86-109, db_lib/AnsibleApp.go• L165-205, db_lib/AnsibleApp.go• L324-364

The playbook command runs from the repository or from a template-selected repository-relative working directory. Ansible receives task environment values and standard task settings, then runs through a managed process that can stop with the task. db_lib/AnsiblePlaybook.go• L25-68, db_lib/AnsiblePlaybook.go• L82-142

References: db_lib/AnsibleApp.go• L86-109 db_lib/AnsibleApp.go• L165-205 db_lib/AnsiblePlaybook.go• L25-142

Terraform preparation

Terraform-family preparation creates the selected working directory, runs initialization, and selects a workspace when the tool supports workspaces. The workspace normally follows the linked inventory, with default as the fallback. A template may provide a temporary backend definition when the project needs to override the source backend. db_lib/TerraformApp.go• L121-194, db_lib/TerraformApp.go• L262-307

Terraform execution separates plan and apply. A plan with no changes ends the run without apply, while apply needs either an allowed auto-approve setting or an explicit confirmation. Terraform state outputs can be collected after a successful run without writing sensitive output values to the task log. db_lib/TerraformApp.go• L309-357, db_lib/TerraformApp.go• L359-427, services/…/local_executor.go• L919-957

References: db_lib/TerraformApp.go• L121-194 db_lib/TerraformApp.go• L262-427 services/…/local_executor.go• L919-957

Playbook discovery

Playbook discovery supplies a short list of likely entry points for template editing. It scans the selected repository content and returns paths relative to the repository root. The selected application controls whether the result contains files or directories.

The discovery rules are:

  • Ansible suggests YAML files and skips common Ansible support directories.
  • Terraform, OpenTofu, Terragrunt, and Pulumi suggest directories.
  • Shell, Python, and PowerShell applications suggest files with their usual extensions.
  • Unknown configured applications do not hide files because the system cannot know their entry-point format.

Results are sorted and capped. Directory browsing moves one level at a time and stays inside the repository, including when the requested path contains traversal syntax or a directory symlink. db/Template.go• L59-89, db_lib/PlaybookFiles.go• L16-56, db_lib/PlaybookFiles.go• L58-134, db_lib/PlaybookFiles.go• L159-209

The selected playbook or application path must be relative to the repository. Validation rejects absolute paths and paths that escape through .., including Windows-style separators. This check protects both saved templates and older data when a task starts. db/playbook_path.go• L10-37, db/Template.go• L472-494, services/…/local_executor.go• L982-991

References: api/…/repository.go• L137-213 db/Template.go• L59-89 db_lib/PlaybookFiles.go• L42-209 db/playbook_path.go• L10-37

Vault support

Vault support gives Ansible tasks access to named password or script sources without storing passwords in task arguments. A template can define password-backed vaults or scripts, and the executor installs the needed access key material before it builds the Ansible command. db/TemplateVault.go• L3-31, services/…/local_executor.go• L1378-1407

Task secrets use a separate one-off Ansible Vault file. Non-secret variables stay in a normal extra-vars file, while secret variables are encrypted and supplied with a temporary vault ID and prompt input. The standard-library vault package reads and writes the Ansible Vault AES256 format and verifies its integrity before decryption. services/…/extra_vars_file.go• L135-213, pkg/…/vault.go• L40-154

At cleanup, installed vault files and other temporary credentials are removed. A wrong password or changed vault content fails authentication rather than returning untrusted plaintext. services/…/local_executor_inventory.go• L138-154, pkg/…/vault.go• L96-145

References: db/TemplateVault.go• L3-31 services/…/local_executor.go• L1378-1407 services/…/extra_vars_file.go• L135-213 pkg/…/vault.go• L40-154

Command environments

Command environments give child tools a controlled view of the server environment. Git and application processes receive PATH, configured variables, and only the server variables explicitly allowed by forwarded-environment settings. Task-specific values are then added for the selected application. db_lib/LocalApp.go• L26-68, db_lib/AnsiblePlaybook.go• L25-50, db_lib/TerraformApp.go• L73-111

The system chooses a task home directory mode to control where tools write user-like data. It can use a project area or the server user's home, and Ansible can receive an isolated template home for its own collections and plugins. On Unix, child applications run in their own process group so cancellation can stop spawned work; Windows uses direct process termination. db_lib/LocalApp.go• L12-23, db/Repository.go• L98-110, db_lib/command_unix.go• L17-39, db_lib/command_windows.go• L14-37

Project host mappings apply to Git and to tools that start Git or SSH themselves. The same mappings reach repository clones, Galaxy dependencies, Terraform modules, and Ansible hosts through the prepared environment and SSH configuration. services/…/local_executor.go• L1417-1445, db_lib/HostConfigLoader.go• L15-48

References: db_lib/LocalApp.go• L12-68 db_lib/AnsiblePlaybook.go• L25-50 db_lib/TerraformApp.go• L73-111 db_lib/command_unix.go• L17-87 db_lib/command_windows.go• L14-37 services/…/local_executor.go• L1417-1445

Content validation

Content validation keeps a task bound to its project repository and to an approved application. Template validation checks the application, required entry content, repository-relative paths, working-directory rules, and branch overrides before the task can use them. The task executor repeats the path checks at run time to protect data created before those checks existed. db/Template.go• L442-524, services/…/local_executor.go• L982-991

Repository validation accepts local paths and supported remote URL forms, requires a branch for remote sources, and validates branch names before Git uses them. Application validation also prevents an unknown application value from becoming an arbitrary system command. db/Repository.go• L220-270, db/Template.go• L447-455

The combined safety boundary is simple: content comes from the repository selected for the project, execution starts from a relative path inside that repository, and the command comes from a known application configuration. db/Repository.go• L249-270, db/playbook_path.go• L10-37, db/Template.go• L447-494

References: db/Repository.go• L220-270 db/playbook_path.go• L10-37 db/Template.go• L442-524 services/…/local_executor.go• L982-991

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Go Git client and command-line Git client aligned with the host-mapping contract.
  • Keep checkout naming, branch override rules, and monorepo sharing aligned so tasks do not use the wrong working tree.
  • Keep application file filters aligned with path validation and the editor's discovery API.
  • Keep Ansible vault IDs, prompt labels, temporary files, and cleanup behavior aligned.
  • Keep forwarded environment rules aligned across Git, Ansible, Terraform, and nested Git or SSH calls.
  • Keep template application validation aligned with the application factory so an accepted value has a safe runner.

Important failure modes

TriggerConsequenceGuard
Go Git is used with project host mappingsRemote access fails instead of using the wrong credentialSelect command-line Git for mapped hosts
A checkout is interrupted or pull failsThe task may run from incomplete or stale sourceValidate repository metadata and recreate the checkout
A template path is absolute or escapes with ..A task could read or execute files outside its repositoryValidate at save time and again at task preparation
A requirements file changes but its cached hash is staleAnsible roles or collections do not match repository contentReinstall and write the new requirements hash
Vault password or ciphertext is invalidAnsible cannot load secrets and the vault reader rejects the dataVerify HMAC before decryption and report the task failure
A task is cancelled while a child tool is runningThe main process may stop while spawned work remainsUse managed process-group or process termination

Key files

FileWhy to read it
db/Repository.goRepository types, checkout identity, URL handling, and validation
db_lib/GitRepository.goShared clone, pull, retry, and checkout lifecycle
db_lib/GitClientFactory.goGit client selection contract
services/…/local_executor.goEnd-to-end task preparation, repository use, vault setup, and cleanup
db_lib/AppFactory.goMapping from template application to runner
db_lib/AnsibleApp.goAnsible dependency preparation and Galaxy access
db_lib/TerraformApp.goTerraform initialization, workspace, plan, apply, and output flow
api/…/repository.goRepository branch and playbook discovery behavior
db_lib/PlaybookFiles.goApplication-aware content discovery rules
pkg/…/vault.goAnsible Vault format and integrity behavior