Skip to content

fix(_common): replace deprecated vars dictionary access - #869

Merged
SuperQ merged 1 commit into
prometheus-community:mainfrom
willbuckner:fix/deprecated-vars-dictionary
Aug 24, 2026
Merged

fix(_common): replace deprecated vars dictionary access#869
SuperQ merged 1 commit into
prometheus-community:mainfrom
willbuckner:fix/deprecated-vars-dictionary

Conversation

@willbuckner

Copy link
Copy Markdown
Contributor

Summary

  • Replace direct membership checks against Ansible's internal vars dictionary with ansible.builtin.varnames lookup.

  • Update all three deprecated variable assertions in the _common role.

  • Preserve detection when deprecated variables are assigned empty values.

    Motivation

ansible-core 2.21 deprecated direct access to its internal vars dictionary, for removal in ansible-core 2.24. Currently I'm seeing these deprecation warnings while doing ansible deployments.

This is an alternative to #793 which is stale since April and failing some CI tests.

Using varnames avoids an undefined variable error when a variable is absent, and checks variable presence independently of its value.

Fixes #853

Validation

  • ansible-lint and yamllint passed with zero failures or warnings.
  • Verified with ansible-core 2.21.2 that an absent variable passes the assertion, and that an explicitly empty deprecated variable fails it.
  • git diff --check passed.

@willbuckner

willbuckner commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Looks like a new set of integration tests ran and I have some failures--investigating.

Edit: Hmm, I'm not sure if my PR is causing this failure or not:

> WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
  
  Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
  Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
  Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Hit:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease
  Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Reading package lists...
  Building dependency tree...
  Reading state information...
  108 packages can be upgraded. Run 'apt list --upgradable' to see them.
  
  WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
  
  Reading package lists...
  Building dependency tree...
  Reading state information...
  docker.io is already the newest version (26.1.3-0ubuntu1~20.04.1).
  0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.
  ERROR    Failed to validate /root/ansible_collections/prometheus/prometheus/roles/bind_exporter/molecule/alternative/molecule.yml
  
  
  Command exited with status 1 after 2.9715819358825684 seconds.
  ERROR: Command "./runme.sh -vvvvvv" returned exit status 1.
  FATAL: The 1 integration test(s) listed below (out of 1) failed. See error output above for details:
  molecule-bind_exporter-alternative
  Run command with stdout: docker exec -i ansible-test-controller-Yj3XHefU sh -c 'tar cf - -C /root/ansible_collections/prometheus/prometheus/tests --exclude .tmp output | gzip'
  Run command with stdin: tar oxzf - -C /home/runner/work/ansible/ansible/ansible_collections/prometheus/prometheus/tests
  FATAL: Command "docker exec ansible-test-controller-Yj3XHefU /usr/bin/env ANSIBLE_TEST_CONTENT_ROOT=/root/ansible_collections/prometheus/prometheus LC_ALL=en_US.UTF-8 /usr/bin/python3.12 /root/ansible/bin/ansible-test integration -v --allow-destructive --containers '{}' --retry-on-error --continue-on-error --diff molecule-bind_exporter-alternative --truncate 0 --color yes --host-path tests/output/.tmp/host-xa1igg4u --metadata tests/output/.tmp/metadata-g58hoj0z.json" returned exit status 1.

@willbuckner

Copy link
Copy Markdown
Contributor Author

I had Codex help me debug the CI failures a bit, and it seems unrelated to my PRs, but in case this helps track it down:

The actual hidden validation error is:

Additional properties are not allowed ('cgroup_parent' was
unexpected)

What happened:

I reproduced the error locally using CI’s exact dependency
versions. I also found the same failure and versions in an
unrelated July 27 run
(https://github.com/prometheus-community/ansible/actions/runs/30250652077),
before PR #869.

At my final check, all 548 failures were Molecule integration jobs;
there were zero failures outside that matrix.

The cleanest likely fix is a separate CI-compatibility change
removing cgroup_parent, because the current Docker plugin neither
accepts nor forwards it. A temporary alternative is pinning
molecule-plugins<26.7.15 while pursuing upstream support.

I don't know enough about molecule nor the rest of your CI system to really propose a fix for the CI failures to be honest.

@SuperQ

SuperQ commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

It seems like one of the config items in our molecule config (cgroup_parent) is not allowed in the new schema test. Will see if I can fix this.

@SuperQ

SuperQ commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

#871 should fix the tests.

Signed-off-by: Will Buckner <1458615+willbuckner@users.noreply.github.com>
@willbuckner
willbuckner force-pushed the fix/deprecated-vars-dictionary branch from ec31793 to 114d992 Compare August 24, 2026 05:49
@github-actions github-actions Bot added bugfix and removed bugfix labels Aug 24, 2026
@willbuckner

Copy link
Copy Markdown
Contributor Author

@SuperQ CI passed this time after your change, thanks for doing that! This should be good to merge whenever.

@SuperQ
SuperQ merged commit b80d272 into prometheus-community:main Aug 24, 2026
631 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Docs Build 📝

Thank you for contributing!✨

This PR has been merged and the docs are now incorporated into main:
https://prometheus-community.github.io/ansible/branch/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment