You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please excuse bad title, I really don't know what to call this. The issue is fairly straight forward to test for. This could affect other modules, but I've only experienced it with the ipaddr filter. The problem is with the input validation being too eager, most clearly visible when trying to use hostvars (see replication steps below).
This patch fixes the issue but it changes the behavior at runtime as well, although I'd argue it's more consistent with other modules.
diff --git a/plugins/filter/ipaddr.py b/plugins/filter/ipaddr.py
index 0ed9865..3e87309 100644
--- a/plugins/filter/ipaddr.py+++ b/plugins/filter/ipaddr.py@@ -11,6 +11,7 @@ from __future__ import absolute_import, division, print_function
from functools import partial
from ansible.errors import AnsibleFilterError
+from ansible.template import AnsibleUndefined
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
AnsibleArgSpecValidator,
@@ -263,6 +264,8 @@ def _ipaddr(*args, **kwargs):
pass
elif isinstance(data["value"], int):
pass
+ elif isinstance(data["value"], AnsibleUndefined):+ pass
else:
raise AnsibleFilterError(
"Unrecognized type <{0}> for ipaddr filter <{1}>".format(
With this patch you will get "test": "VARIABLE IS NOT DEFINED!" at runtime instead of an exception.
The output of hostvars with the patch is consistent with other modules, they're displayed as is (in raw form) until actually used at runtime where they're evaluated. Someone more familiar with the code base may decide if this is the right way to fix it, if it is I'd gladly open a PR if desired.
[defaults]inventory = hosts.yml
# This is here so I could test my changes, it only contains a clone of this repo's main branchcollections_path = ~/src/ansible
SUMMARY
Please excuse bad title, I really don't know what to call this. The issue is fairly straight forward to test for. This could affect other modules, but I've only experienced it with the
ipaddr
filter. The problem is with the input validation being too eager, most clearly visible when trying to usehostvars
(see replication steps below).This patch fixes the issue but it changes the behavior at runtime as well, although I'd argue it's more consistent with other modules.
With this patch you will get
"test": "VARIABLE IS NOT DEFINED!"
at runtime instead of an exception.The output of
hostvars
with the patch is consistent with other modules, they're displayed as is (in raw form) until actually used at runtime where they're evaluated. Someone more familiar with the code base may decide if this is the right way to fix it, if it is I'd gladly open a PR if desired.ISSUE TYPE
COMPONENT NAME
ansible.utils.ipaddr
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Arch, this issue is OS agnostic.
STEPS TO REPRODUCE
Inventory
Config
EXPECTED RESULTS
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: