awx_collection: dict-typed variables fields are never idempotent and are stored as JSON
Please confirm the following
- I agree to follow this project's code of conduct.
- I have checked the current issues for duplicates.
- I understand that AWX is open source software provided for free and that I might not receive a timely response.
- I am NOT reporting a (potential) security vulnerability. (These should be emailed to
[email protected]instead.)
Bug Summary
Assisted-by: Claude Opus 5
Drafted with AI assistance and checked by hand: every reproduction, version number and patch behavior below was verified against a live controller .
Four fields are declared type='dict' by the modules but stored by the API as a text blob: extra_vars
(job_template, workflow_job_template), variables (inventory, host, group) and source_vars
(inventory_source). Nothing normalizes between the two forms, and objects_could_be_different() compares
them directly — a dict against a string, which can never be equal.
That single gap produces three defects:
- The modules are never idempotent for any object that sets one of these fields. Every run reports
changed, even when the stored value already matches. - Values are stored as JSON rather than YAML — reported in #14918.
- There is no way to clear one of these fields — reported in #14842.
A pull request fixing all three, with unit tests, accompanies this report.
AWX version
25.4.0, with awx_collection 24.6.1 (the latest published version)
Select the relevant components
- UI
- UI (tech preview)
- API
- Docs
- Collection
- CLI
- Other
Installation method
kubernetes
Modifications
no
Ansible version
ansible-core 2.21.4
Operating system
Ubuntu 24.04
Web browser
No response
Steps to reproduce
From a new installation, using only the demo resources it ships with. Run this playbook twice:
- hosts: localhost
connection: local
gather_facts: false
tasks:
- awx.awx.job_template:
name: repro-extra-vars
project: Demo Project
playbook: hello_world.yml
inventory: Demo Inventory
extra_vars:
tt: ttFor comparison, the same template declared without the field is idempotent:
- awx.awx.job_template:
name: repro-extra-varsDeclaring the stored form instead of a dict is rejected outright, so there is no spelling that compares equal:
argument 'extra_vars' is of type str and we were unable to convert to dict:
dictionary requested, could not parse JSON or key=valueExpected results
The first run reports changed (it creates the template). The second run reports ok, because the stored
value already matches what is declared.
Actual results
The second run reports changed, and so does every run after it. Inspecting the template afterwards shows
extra_vars stored as {"tt": "tt"} rather than as YAML, and there is no way to return it to empty.
Additional information
Cause. objects_could_be_different() in awx_collection/plugins/module_utils/controller_api.py does
if old_field != new_field, where old_field is the stored string and new_field is the declared dict.
The same template's survey_spec compares correctly, so the comparison logic is sound elsewhere; the defect
is specific to these text-blob fields.
Why it matters beyond cosmetics. It rules out --check as a preview for configuration-as-code
workflows. Any object setting one of these fields produces a permanent false positive, so "would change"
stops carrying information, and a reviewer cannot tell a real diff from this one.
The fix, submitted as a pull request alongside this issue. Two helpers in
awx_collection/plugins/module_utils/controller_api.py, used in both directions: parse the stored string
before comparing, and serialize dicts to YAML when sending. Verified against a live AWX 25.4.0:
| case | before | after |
|---|---|---|
| identical value | changed |
ok |
| genuinely different value | changed |
changed |
| dict → stored form | {"tt": "tt"} |
---\ntt: tt |
| empty dict | cannot clear | clears the field |
| unparseable stored value | — | compared as an opaque string |
On the fallback for unparseable values: if the stored text does not parse as YAML, the patch compares it as the opaque string it is rather than raising. A hand-mangled field therefore keeps today's behavior instead of becoming a new failure mode. Happy to make that strict instead if you would rather it surface.
On the relationship to #14842 and #14918: those report the write side of this same normalization gap, and the patch resolves both as a side effect. I have opened this separately because the idempotence failure is a distinct symptom with different consequences, and because it argues for fixing the handling in one place rather than per-module. If you would rather consolidate all three into one issue, say which and I will move the detail there — that seems better decided with all three symptoms visible than by guessing up front.
Source: ansible/awx