Inventory Host class's __repr__/__str__
can return None (TypeError)
#24545
Labels
affects_2.3
This issue/PR affects Ansible v2.3
bug
This issue/PR relates to a bug.
c:inventory/contrib_script
inventory
Inventory category
support:core
This issue/PR relates to code supported by the Ansible Engineering Team.
traceback
This issue/PR includes a traceback.
ISSUE TYPE
COMPONENT NAME
Ansible, inventory script
ANSIBLE VERSION
CONFIGURATION
No changes to
ansible.cfg
OS / ENVIRONMENT
N/A
SUMMARY
Ansible's Inventory Host class's
__repr__/__str__
can return None. This is not allowed in Python and raises TypeError.STEPS TO REPRODUCE
I was using the Cobbler inventory script and it created an Ansible Host object that had no hostname. This alone is unexpected (seems to be a bug in the Cobbler inventory script (#24546)), but that is not what this issue is about. While trying to debug the problem, I tried to print out the host that was having issues. However even just printing the object was causing Python to crash.
This is a result of Host object returning just
self.name
(which isNone
) from its__repr__
method. This is not allowed in Python.And yet, the Host
__init__
defaults the name toNone
, so this failure is actually the default case.The simplest possible example is probably:
EXPECTED RESULTS
I would expect it to print a string representation of the Host, (perhaps something like "Host:{self.name}") instead of crashing Python.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: