Problem: Concurrent tasks sharing a static inventory delete each other's inventory file (task runs with empty inventory and reports Success)
Issue
(Written by an AI)
For static / static-yaml inventories, the temporary inventory file is named after the inventory ID, not the task ID:
// services/tasks/LocalJob_inventory.go (v2.18.x), local_executor_inventory.go (v2.19+, develop)
func (t *LocalJob) tmpInventoryFilename() string {
if t.Inventory.Repository == nil {
return "inventory_" + strconv.Itoa(t.Inventory.ID)
}
...Every task writes this file when it starts (installStaticInventory() → os.WriteFile) and removes it when it ends (destroyInventoryFile() → os.Remove). All concurrent tasks of a project that use the same inventory share <tmp>/project_<P>/inventory_<ID>.yml, and the first one to finish deletes the file the others are using. Nothing locks it.
If a task finishes between another task's installing static inventory and the moment its ansible-playbook parses the inventory, that second task runs with no inventory. Every play is skipped with no hosts matched, and the task ends with Success. Nothing tells you the task did nothing.
Steps to reproduce
- Create a Static YAML inventory:
all: hosts: localhost: ansible_connection: local - Create two templates that use it. They must be two different templates, so they run in parallel with default settings.
- A:
- hosts: all gather_facts: false tasks: - ansible.builtin.ping: - B:
- hosts: all gather_facts: false tasks: - ansible.builtin.command: sleep 30 - ansible.builtin.stat: path: "{{ ansible_inventory_sources[0] }}" register: inv - ansible.builtin.assert: that: inv.stat.exists fail_msg: "{{ ansible_inventory_sources[0] }} was deleted by another task"
- A:
- Run B. While it sleeps, run A.
Expected: B's assertion passes. A task's inventory file exists for the task's whole lifetime.
Actual: B's assertion fails. When A finished, it removed the file B is using.
In production, the window that matters is the ~0.5 s between writing the file and Ansible parsing it. We hit it regularly: an orchestration playbook launches deployment steps of several templates in parallel through the API, all on the same inventory. It affected 11 of our last ~500 tasks, and three steps of a single deployment were silently skipped this morning.
Impact
Ansible (task execution)
Installation method
Package
Database
No response
Browser
No response
Semaphore Version
v2.18.1-dac3cdc-1777928283 Code checked unchanged in v2.18.30, v2.19.14, v2.20.0-alpha2 and develop.
Ansible Version
ansible [core 2.21.0]
config file = None
configured module search path = ['/home/semaphore/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/semaphore/ansible/lib/python3.13/site-packages/ansible
ansible collection location = /home/semaphore/.ansible/collections:/usr/share/ansible/collections
executable location = /home/semaphore/ansible/bin/ansible
python version = 3.13.5 (main, Jul 15 2026, 20:25:40) [GCC 14.2.0] (/home/semaphore/ansible/bin/python3)
jinja version = 3.1.6
pyyaml version = 6.0.3 (with libyaml v0.2.5)Logs & errors
Output of the affected task. Another task using the same inventory (id 58) finished at 07:09:52.667, between this task writing the file (07:09:52.521) and failing to parse it (07:09:53.063):
07:09:52 installing static inventory
07:09:53 [WARNING]: Unable to parse /var/lib/semaphore/tmp/project_4/inventory_58.yml as an inventory source
07:09:53 [WARNING]: No inventory was parsed, only implicit localhost is available
07:09:53 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
07:09:53 [WARNING]: Could not match supplied host pattern, ignoring: app10
07:09:53 PLAY [Backend installation] ***********************************************
07:09:53 skipping: no hosts matched
07:09:53 PLAY RECAP *********************************************************************Task status: Success. No Failed to parse ... with <plugin> plugin line follows the warning: every inventory plugin skips a path that doesn't exist, which fits the file having been deleted. The same inventory parsed fine in the previous task on the same host, 30 s earlier.
Manual installation - system information
Debian 13, Semaphore running as a systemd service, TMP path /var/lib/semaphore/tmp Reverse proxy: Caddy
Configuration
- All templates of the project use one Static YAML inventory (a netbox.netbox.nb_inventory plugin config). The content doesn't matter; the minimal inventory from the reproduction triggers it too.
- "Allow parallel tasks" is not enabled. The race only needs two different templates running at the same time.
- Tasks are started through the API by an orchestration template, several views in parallel.
- Local execution, no remote runner.
Additional information
- Regression: 8420ae94 ("also take into account non repository inventories", April 2025, first released in v2.14.0), a follow-up to #2922. Before it, the file was named
inventory_<task ID>. - Not covered by #4023: its
KeyLockonly serializes repository and git inventory directories, not static inventory files. - Related: #2902 (task shows Success when the inventory couldn't be loaded).
- Suggested fix: put the task ID back in the filename for non-repository inventories, e.g.
"inventory_" + strconv.Itoa(t.Inventory.ID) + "_" + strconv.Itoa(t.Task.ID).destroyInventoryFile()already deletes the file when the task ends, so temp files wouldn't pile up again (#1133). - Workaround: setting
ANSIBLE_INVENTORY_UNPARSED_FAILED=Truein the variable group's environment variables makes the task fail instead of reporting Success. It doesn't prevent the race.
Source: semaphoreui/semaphore