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
AnsibleUnsafeText not casted to basestring when calling from_yaml #70357
Comments
Files identified in the description: If these files are incorrect, please update the |
Related PR: #65002 We could potentially merge the above, and use it within
|
Can you verify if #65002 resolves your issue? |
Yes, it does. |
I wanted to understand why this is happening, and it led me to the fact that salt is doing something that is probably not the best idea. However, in Ansible 2.10 this would no longer happen.
In the end, I'm going to make some changes to explicitly select the |
I've also just hit this. As soon as python2-salt goes in, i'm getting this: Remove python2-salt, and it works again. |
In Ansible 2.10 this will no longer be a problem. Salt does a bad thing in its code, by monkey patching Unfortunately due to the way the salt code is written, there isn't much we can do here In Ansible versions before 2.10. |
Closing as per above |
SUMMARY
Using a Jinja2 expression using
lookup()
andfrom_yaml
produces an error, if the C-Extension of PyYAML is used.The reason seems to be that Ansible's
from_yaml
-filter calls the YAML-parser with an instance ofAnsibleUnsafeText
The C-extension of PyYAML explicitly denies subclasses of string/basestring: https://github.com/yaml/pyyaml/blob/23c952fe08b2e7ea0f8d7673f45b17547e331f4b/ext/_yaml.pyx#L299
See also https://bugs.launchpad.net/ubuntu/+source/ansible/+bug/1880226
ISSUE TYPE
COMPONENT NAME
core
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
CentOS 7
In my case Ansible only uses the C implentation of PyYAML, if
salt
has been installed from https://repo.saltstack.com/yum/redhat/7/x86_64/3000/I do not use the PyYAML package from the saltstack-repository and even if I do it does not work.
As soon as I uninstall the
salt
-package, Ansible uses the native-python YAML-parser of PyYAML and the filter works.STEPS TO REPRODUCE
It is important that Ansible uses PyYAML with the
libyaml
C-library.If it uses the YAML-parser written in plain python the error does not occur.
For me this was -strangely- only the case if
salt
was installed (see OS / ENVIRONMENT)testfile.yaml:
EXPECTED RESULTS
The file content read by
lookup()
should be accepted by thefrom_yaml
-filter.ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: