Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use namespaced ansible_facts #44

Closed
wants to merge 2 commits into from

Conversation

cognifloyd
Copy link
Contributor

@cognifloyd cognifloyd commented Sep 25, 2020

If ansible's INJECT_FACTS_AS_VARS is disabled, then this role will not work. So, use the namespaced version under ansible_facts.

https://docs.ansible.com/ansible/2.8/reference_appendices/config.html#inject-facts-as-vars

@geerlingguy
Copy link
Owner

@cognifloyd - This is the first time I've ever seen INJECT_FACTS_AS_VARS; what's the use case for that? There are thousands of roles (and hundreds I maintain) using the built-in facts with ansible_ prefix, and if this is something that's in common use, I'm surprised nobody else has ever complained about it...

Most of the blog posts and docs online refer to the ansible_ facts too (e.g. the seminal result that is always at the top of Google results: https://raymii.org/s/tutorials/Ansible_-_Only_if_on_specific_distribution_or_distribution_version.html).

@cognifloyd
Copy link
Contributor Author

cognifloyd commented Sep 28, 2020

This was introuduced in Ansible 2.5 (released in 2018). Here's the relevant section of 2.5 changelog's Major Changes (added in ansible/ansible@9c629f8):

Added fact namespacing; from now on facts will be available under ansible_facts namespace (for example: ansible_facts.os_distribution) without the ansible_ prefix. They will continue to be added into the main namespace directly, but now with a configuration toggle to enable this. This is currently on by default, but in the future it will default to off.

Reasoning for this change is in ansible/ansible#18445 (comment)

it avoids collisions with existing vars by making sure all facts are restricted to ansible_facts.

And here's a section of the 2.5 porting guide. However the doc change wasn't added to the 2.5 porting guide until 2.7:

I follow the porting guides. As such, I switch to new behavior as soon as possible so that new things I write have the longest life span possible; I ensure that I have this setting as True when I run my playbooks so that I'm actively working with the new behavior instead of being passively surprised when the default changes on me.

This change is safe for ansible 2.5+. Only roles that need to support <2.4 (EOL) need to continue supporting the old fact names. So, the choice is to remain backwards-compatible and risk forwards-compatibility, or to switch to the namespaced facts and be fully forwards-compatible but only backwards compatible down to ansible 2.5.

If you don't want to use the namespaced vars, that's a fair choice. In that case, I will look for an alternative role, or continue to maintain another EPEL role.

@cognifloyd
Copy link
Contributor Author

Also, the minimum ansible version was bumped in #45 from 2.4 to 2.5 to accomodate the version test (instead of version_compare). That's no longer needed since you removed the fingerprint addition, so if you still need to support 2.4, then that should be dropped back down to 2.4. If you don't need 2.4, then I hope you'll merge this; using ansible_facts namespace is the best-practice in all of the ansible docs.

If ansible's INJECT_FACTS_AS_VARS is disabled, then these roles will not work.
So, use the namespaced version under ansible_facts.

Namespaced facts was added in Ansible 2.5.

https://docs.ansible.com/ansible/2.8/reference_appendices/config.html#inject-facts-as-vars
@cognifloyd
Copy link
Contributor Author

Rebased on master

@stale
Copy link

stale bot commented Dec 27, 2020

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark pull requests as stale.

@stale stale bot added the stale label Dec 27, 2020
@stale
Copy link

stale bot commented Jan 27, 2021

This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.

@stale
Copy link

stale bot commented May 21, 2023

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark pull requests as stale.

@stale stale bot added the stale label May 21, 2023
defaults/main.yml Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the stale label Jul 14, 2023
Copy link

This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

@github-actions github-actions bot added the stale label Nov 17, 2023
@cognifloyd
Copy link
Contributor Author

@geerlingguy Do you have a plan for this PR? The stalebot is vociferously opposed to it.

@github-actions github-actions bot removed the stale label Nov 24, 2023
Copy link

This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

@github-actions github-actions bot added the stale label Mar 29, 2024
Copy link

This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

@github-actions github-actions bot closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants