-
Notifications
You must be signed in to change notification settings - Fork 148
[config_drive] Fix conditional to handle NoneType properly #3683
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
Closed
holser
wants to merge
1
commit into
openstack-k8s-operators:main
from
holser:ansible-core-2.17.14_config_drive
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed.
The varialbe is defined in the role default, see: https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/config_drive/defaults/main.yml#L31-L32 - so it will be None or some value the user provided. The
is not nonetest is safe here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with default({}) it's a safe mechanism if someone will define it as
However, this change is required for Ansible 2.17 as cifmw_config_drive_networkconfig should be defined before checking length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is'nt
cifmw_config_drive_networkconfig:==cifmw_config_drive_networkconfig: nullSo the
is not nonewill skip the task in that case?If you define:
And then do "cifmw_config_drive_networkconfig | default({})" - what is the result? I think it would be
cifmw_config_drive_networkconfig == (null|none)- it wont enter the| default({}because cifmw_config_drive_networkconfig is defined asnull|nonevalue?I think
| defaulthere is "dead code" it cannot happen?--- I asked Cursor/Claude AI:
Ansible conditionals and patch necessity
Exported on 2/24/2026 at 15:15:16 GMT+1 from Cursor (2.5.20)
User
I want you to take a look at commit 9742844
It is suopposed to fix something related to Ansible 2.16+ that require conditionals to return a boolean value.
I think the patch is not needed.
My reasoning.
This is not needed.
The varialbe is defined in the role default, see: https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/config_drive/defaults/main.yml#L31-L32 - so it will be None or some value the user provided. The is not none test is safe here. @roles/config_drive/defaults/main.yml:31-32
The change made to the conditions: @roles/config_drive/tasks/main.yml:54 @roles/config_drive/tasks/main.yml:63
--- a/roles/config_drive/tasks/main.yml
+++ b/roles/config_drive/tasks/main.yml
@@ -51,8 +51,7 @@
register: _user_data_change
when:
ansible.builtin.template:
backup: true
src: "user-data.j2"
@@ -61,9 +60,7 @@
register: _net_data_change
ansible.builtin.template:
backup: true
src: "network-config.j2"
Is'nt
cifmw_config_drive_networkconfig:==cifmw_config_drive_networkconfig: nullSo the
is not nonewill skip the task in that case?If you define:
And then do "cifmw_config_drive_networkconfig | default({})" - what is the result? I think it would be
cifmw_config_drive_networkconfig == (null|none)- it wont enter the| default({}because cifmw_config_drive_networkconfig is defined asnull|nonevalue?I think
| defaulthere is "dead code" it cannot happen?Cursor
I'll help you analyze this commit and the Ansible variable handling behavior. Let me first look at the commit and the relevant files.
You are absolutely correct! Your analysis is spot-on. Let me explain why:
The Critical Difference
In YAML/Ansible:
cifmw_config_drive_userdata:(no value) is equivalent tocifmw_config_drive_userdata: nullNone/nullHow Jinja2
defaultFilter WorksThe
defaultfilter only provides a fallback value when a variable is UNDEFINED, not when it's defined asNone:Why the Original Code Was Correct
Original code:
null(as defined in defaults),is not nonereturnsFalse→ task is skipped ✅New code (from the patch):
null,default({})does nothing (returnsNone)None | length > 0tries to get the length ofNone→ ERROR ❌The Fix to Make
defaultWorkIf you wanted to use
default, you'd need:The
trueparameter makes the default filter treatNone/nullvalues as undefined.Or, remove these variables from the defaults file entirely so they're truly undefined.
Conclusion
Your reasoning is correct. The patch in commit
974284426086b6b863c25e02b6cb5e832ec87173is incorrect and would actually break the functionality. The| default({})is indeed "dead code" as you suspected - it cannot trigger because the variables are defined (as null) in the defaults file.The original
is not nonecheck was the correct approach for this scenario.