telegraf
telegraf copied to clipboard
Fix for 'str object' has no attribute 'name'
I started seeing the following error:
TASK [rossmcdonald.telegraf : Set templatized Telegraf configuration] *************************************************************************************************************************************************
task path: /home/user/.ansible/roles/rossmcdonald.telegraf/tasks/configure.yml:14
The full traceback is:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 1116, in do_template
res = ansible_concat(rf)
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/native_helpers.py", line 88, in ansible_concat
return ''.join([to_text(v) for v in nodes])
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/native_helpers.py", line 88, in <listcomp>
return ''.join([to_text(v) for v in nodes])
File "<template>", line 231, in root
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 268, in wrapper
ret = func(*args, **kwargs)
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 647, in _ansible_finalize
return thing if _fail_on_undefined(thing) is not None else ''
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 619, in _fail_on_undefined
elif is_sequence(data):
File "/home/user/.local/lib/python3.10/site-packages/ansible/module_utils/common/collections.py", line 94, in is_sequence
if not include_strings and is_string(seq):
File "/home/user/.local/lib/python3.10/site-packages/jinja2/runtime.py", line 852, in _fail_with_undefined_error
raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'str object' has no attribute 'name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.10/site-packages/ansible/plugins/action/template.py", line 138, in run
resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
File "/home/user/.local/lib/python3.10/site-packages/ansible/template/__init__.py", line 1153, in do_template
raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: 'str object' has no attribute 'name'
fatal: [dev17.smartkyc.com]: FAILED! => changed=false
msg: 'AnsibleUndefinedVariable: ''str object'' has no attribute ''name'''
I am not sure at which point this started happening - I only discovered when I wanted to add a new telegraf plugin to my infrastructure. By the looks of it the result of the old style concatenation results in a string now instead of a list. This fixes the issue for me but I didn't test more than this.