Actions
Issue #8060
closedsettings.py not always properly fed. Difference between false / False
Status:
CLOSED - NOTABUG
Priority:
Normal
Assignee:
Category:
Installer - Moved to GitHub issues
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Quarter:
Description
Due to the way safe_eval
works in ansible/ansible
, the following line ends up not providing the right content https://github.com/pulp/pulp_installer/blob/master/roles/pulp_common/templates/settings.py.j2#L2.
---
- hosts: localhost
gather_facts: false
vars:
test_1: test_1
test_bool: false
tasks:
- debug:
msg: '{{ test_1 | string | capitalize }}'
- debug:
msg: '{{ test_bool | string | capitalize }}'
Output
PLAY [localhost] **********************************************************************************************************************************
TASK [debug] **************************************************************************************************************************************
ok: [localhost] =>
msg: Test_1
TASK [debug] **************************************************************************************************************************************
ok: [localhost] =>
msg: false
PLAY RECAP ****************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
After talking with the Ansible engineering team this is the reason that has been provided
This is happening because of safe_eval - a function we added in Ansible templating to convert some of the Jinja2 results, which are always strings, to their original type but as you can see it does not always work as you’d want (native jinja feature is another attempt to solve this). So if templating sees "True" (which is the result of '{{ test_yes | bool | string | upper }}') it converts it back to bool and so you get true in the debug output. safe_eval can be bypassed by using one of the STRING_TYPE_FILTERS (https://docs.ansible.com/ansible/2.10/reference_appendices/config.html#string-type-filters), which is why false | bool | string | capitalize | string works.
Updated by spredzy about 3 years ago
- Status changed from NEW to CLOSED - NOTABUG
Actions