Problem: Ansible host_vars not loaded from correct branch in Semaphore
Issue
Bug Description
When running a playbook in Semaphore using a non-main branch (e.g. fixing issue XX), the host_vars are not read from the checked-out branch, but instead from the main branch.
Environment
Semaphore version:
Tested on v2.13.13 and v2.14.7 (latest)
Ansible: Default bundled version
SEMAPHORE_TMP_PATH: /tmp/semaphore/
Observed Behavior
When using branch fixing issue XX, Semaphore creates:
/tmp/semaphore/project_1/repository_1_template_16_inventory_1 → points to branch main
/tmp/semaphore/project_1/repository_3_template_16 → points to branch fixing issue XX
The inventory is loaded from the main branch, not from the working branch where updated host_vars live.
Problem
Even though I have modified host_vars/sync01.yaml in fixing issue XX, Semaphore still uses the outdated version from main.
Expected Behavior
The host_vars (and group_vars) should be read from the currently selected Git branch for the playbook, not defaulted from main.
Steps to Reproduce
Create a new branch fixing issue XX from main
Modify a host_vars/
Push the branch and configure a template to use it
Run the template
Workaround Tried
Manually verified the correct file exists in repository_3_template_16
Confirmed that inventory path points to another directory tied to main
Upgraded to latest Semaphore v2.14.7 — issue persists
📎 Additional Notes This breaks playbook behavior that depends on up-to-date variables.
Makes it difficult to test features in Git branches without merging into main.
Impact
Ansible (task execution)
Installation method
Docker
Database
Postgres
Browser
Chrome
Semaphore Version
Ansible Version
ansible [core 2.17.9]
Logs & errors
VARIABLE IS NOT DEFINED
Manual installation - system information
No response
Configuration
No response
Additional information
No response
Yes, we need to add field "branch" to inventory too.
@Thanoonazad you don't need to provide inventory repository if it the same like in template.
Template repository will be used by default if you don't provide repo for inventory.
@fiftin Hi,
well I have 2 repositories, the first one is for the main branch "ansible-playbooks" and the secound one is for branches "ansible-playbooks-mr". Both URL of the repository are the same, but a diffrent branch.
In my task templates I use the repositorie with the branch "ansible-playbooks-mr" and I did select the Inventory of the main repository
Under the Inventory I have created an Inventory and I did also define the repository of the main branch.
Is it possible maybe here is the problem with the Inventory file of the main branch used by the branch?
Thank you for your help