-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
hostvars['name'] will not be converted to strings in the proper contexts (hostvarsvars issue) #66916
Comments
Files identified in the description: If these files are inaccurate, please update the |
Same problem on my side. The If I use the build in Jinja2 filter variable:
key: value data_file.yaml.j2:
https://jinja.palletsprojects.com/en/2.11.x/templates/#tojson |
This error is thrown even when used in I have found that it does not fail in virtualenv, but throws when using Ansible from system package (ArchLinux, Ansible 2.9.9). In virtualenv, however the same version works (pyenv virtualenv using system Python). |
I think I found where the problem is. Looks like there is a bug in the The When I remove this underlying libyaml from my Ansible host system, this filter works perfect.
After all these steps the filter worked again. For me it looks like there is a bug in either the pyyaml module or the libyaml-0-2 lib. Have not enough time to troubleshoot this further. |
this is a HostVarsVars issue (the object you get from hostvars['host'] which tries to simulate a dictionary), it is not properly 'stingifiying' as dictionaries normally do. The fix would be to force this behaviour, which is not done as it would require templating every value and the object itself exists to avoid that for performance reasons. |
A colleague of mine, who is running Focal has encountered this issue as well. We have a git repo w/ a Vagrantfile using Ansible as provisioner, and his machine fails to process every single hostvars magic variable use case. I am running Bionic and have no issues. The two of us have spent the day trying to figure out why things work for me and not for him when using Psuedo removing libyaml as @JoelKle mentions is not a viable work-around due to Vagrant (ruby under the hood) relying on libyaml. |
FWIW: I was able to workaround this issue (in my use case) by first converting the hostvars to json, then back, and then pushing that result through the "{{ hostvars[inventory_hostname] | to_json | from_json | to_nice_yaml(indent=2)}}" |
This has been resolved in #72607 and will be included in ansible-core 2.12 If you have further questions please stop by IRC or the mailing list:
|
SUMMARY
When using the templating filter
to_nice_yaml
(orto_yaml
) and running on SLES 12sp5, an error is thrown saying that thevalue must be a string
. On the same system, if the Ansible version used is less than 2.8.0, the error is not thrown.I also tested with RHEL 7.2, 7.7, and 8.0 as well as SLES 12sp3, sp4, and SLES 15. For each environment I tested Ansible 2.7.0, 2.7.16, 2.8.0, 2.8.8, 2.9.0, and 2.9.4. The filter worked correctly in each of these environments.
ISSUE TYPE
COMPONENT NAME
(may affect other templating filters)
ANSIBLE VERSION
I also tested Ansible 2.8.0, 2.8.8, and 2.9.0, all of which threw the same error.
CONFIGURATION
OS / ENVIRONMENT
SLES 12sp5
STEPS TO REPRODUCE
On a SLES 12sp5 environment with Ansible 2.8.0 - Ansible 2.9.4:
test.yml:
data_file.yaml.j2:
EXPECTED RESULTS
From Ansible 2.7.16 on SLES 12sp5:
ACTUAL RESULTS
From Ansible 2.9.4 on SLES 12sp5:
The text was updated successfully, but these errors were encountered: