ansible/ansible · error · TypeError
'{0!r}' is not a string and conversion is not allowed
Error message
'{0!r}' is not a string and conversion is not allowed What it means
Error "'{0!r}' is not a string and conversion is not allowed" thrown in ansible/ansible.
Source
Thrown at lib/ansible/module_utils/common/validation.py:350
:arg value: Value to validate or convert to a string
:arg allow_conversion: Whether to convert the string and return it or raise
a TypeError
:returns: Original value if it is a string, the value converted to a string
if allow_conversion=True, or raises a TypeError if allow_conversion=False.
"""
if isinstance(value, str):
return value
if value is None:
return '' # approximate pre-2.19 templating None->empty str equivalency here for backward compatibility
if allow_conversion:
return to_native(value, errors='surrogate_or_strict')
msg = "'{0!r}' is not a string and conversion is not allowed".format(value)
raise TypeError(to_native(msg))
def _check_type_str_no_conversion(value) -> str:
return check_type_str(value, allow_conversion=False)
def check_type_list(value):
"""Verify that the value is a list or convert to a list
A comma separated string will be split into a list. Raises a :class:`TypeError`
if unable to convert to a list.
:arg value: Value to validate or convert to a list
:returns: Original value if it is already a list, single item list if a
float, int, or string without commas, or a multi-item list if a
comma-delimited string.
"""View on GitHub (pinned to 9cf16a4aca)
Solutions
- Pass a string value, or enable conversion if the caller supports it.
- Quote the value in the playbook to force string type.
When it happens
Trigger: Thrown at lib/ansible/module_utils/common/validation.py:350 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15).
Data as JSON: /api/errors/f0ef139037420241.
Report an issue: GitHub.