awx.awx.inventory always reports changed for a standard inventory because kind is sent as null
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
awx.awx.inventory is never idempotent for a standard inventory. inventory_fields is built with
'kind': kind and 'host_filter': host_filter unconditionally, so when either is not supplied the
module sends None. A standard inventory stores kind as '', None != '', and the module reports
changed and issues a PATCH on every run.
The other optional fields in the same dict literal are already guarded — description, variables
and prevent_instance_group_fallback each go through if ... is not None — so the fix is to treat
kind and host_filter the same way.
Declaring kind: '' explicitly is a workaround when calling the module directly, but not through
infra.controller_configuration, whose field expressions are default(<value>, true): that true
treats the empty string as undeclared and restores the omission. The effect is that a playbook
managing inventories through that collection reports every inventory as changed on every run, which
is being reported there separately.
AWX version
25.4.0 (packaged by a third-party distribution — see Modifications), with the awx.awx collection at 24.6.1. Code paths confirmed unchanged on devel at 4c290176ef.
Select the relevant components
- UI
- UI (tech preview)
- API
- Docs
- Collection
- CLI
- Other
Installation method
kubernetes
Modifications
yes
Ansible version
ansible-core 2.16.19
Operating system
Ubuntu 24.04 execution environment
Web browser
No response
Steps to reproduce
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create a standard inventory
awx.awx.inventory:
name: kind-repro
organization: Default
- name: Declare it again, unchanged
awx.awx.inventory:
name: kind-repro
organization: Default
register: second
- debug:
msg: "second run changed={{ second.changed }}"Expected results
The second task reports changed=false. Nothing about the inventory differs from what was declared.
Actual results
The second task reports changed=true, and every subsequent run does the same. The module sends
kind: null against a stored kind of ''.
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "second run changed=true"
}Additional information
Field assembly on devel (awx_collection/plugins/modules/inventory.py):
inventory_fields = {
'name': ...,
'organization': org_id,
'kind': kind,
'host_filter': host_filter,
}
if prevent_instance_group_fallback is not None:
inventory_fields['prevent_instance_group_fallback'] = prevent_instance_group_fallback
if description is not None:
inventory_fields['description'] = description
if variables is not None:
inventory_fields['variables'] = json.dumps(variables)host_filter is the same shape of defect but is not usually visible, because a standard inventory
stores host_filter as null and the module happens to send None as well. Supplying
host_filter: '' — what a caller asking for "no host filter" would write — makes it report
changed forever too.
A fix is attached as a PR: guard both fields with is not None, matching the three below them, and
read inventory_fields.get('kind') in the standard-to-smart guard that follows.
Measured on a controller with 71 standard inventories: all 71 report changed on every run before
the change and none after.
Source: ansible/awx