Skip to content
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

quote filter doesn't handle None #32174

Closed
wenottingham opened this issue Oct 26, 2017 · 4 comments · Fixed by #71473
Closed

quote filter doesn't handle None #32174

wenottingham opened this issue Oct 26, 2017 · 4 comments · Fixed by #71473
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@wenottingham
Copy link
Contributor

wenottingham commented Oct 26, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

quote filter

ANSIBLE VERSION
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/notting/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Sep  5 2017, 08:53:59) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
CONFIGURATION
ANSIBLE_SSH_PIPELINING(/etc/ansible/ansible.cfg) = True
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
OS / ENVIRONMENT

Fedora 26

SUMMARY

quote filter does not work with the example chaining syntax on http://docs.ansible.com/ansible/latest/playbooks_filters.html#omitting-parameters

STEPS TO REPRODUCE

Playbook:

---
- hosts: all
  connection: local
  gather_facts: false
  tasks:
    - name: test with bool
      debug: msg="{{ undefined_var|default(None)|bool or omit }}"

    - name: test with quote
      debug: msg="{{ undefined_var|default(None)|quote or omit }}"
EXPECTED RESULTS
PLAY [all] ***************************************************************************************************************************

TASK [test with bool] ****************************************************************************************************************
ok: [localhost] => {
    "msg": "Hello world!"
}

TASK [test with quote] ***************************************************************************************************************
ok: [localhost] => {
    "msg": "Hello world!"
}

PLAY RECAP ***************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
ACTUAL RESULTS
PLAY [all] ***************************************************************************************************************************

TASK [test with bool] ****************************************************************************************************************
ok: [localhost] => {
    "msg": "Hello world!"
}

TASK [test with quote] ***************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ undefined_var|default(None)|quote or omit }}): 'NoneType' object is not iterable"}
	to retry, use: --limit @/usr/local/prog/test-playbook/test1.retry

PLAY RECAP ***************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1  
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 26, 2017
@sivel
Copy link
Member

sivel commented Oct 26, 2017

I’m not sure it should work with None. The goal is to quote the value for shell usage. Even if it did work, I’d expect it to perhaps cast to string first, which wouldn’t work in your example.

It shouldn’t just act as a pass through for non strings as that could be dangerous in itself.

@sivel
Copy link
Member

sivel commented Oct 26, 2017

Maybe something like the following is actually what you want:

{{ omit if not undefined_var|default(None) else undefined_var|quote }}

@wenottingham
Copy link
Contributor Author

That may be... mostly was just following the example given in the docs. Should that be updated?

@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Oct 26, 2017
@sivel
Copy link
Member

sivel commented Oct 26, 2017

Ah, last night when looking at the docs I didn't see that format mentioned. It seems to be in the Note section.

I'd be curious how many filters would actually work with that scenario. I'm guessing not too many.

I think updating the docs would probably be a good idea.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 17, 2018
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Nov 26, 2018
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Dec 12, 2018
sivel added a commit to sivel/ansible that referenced this issue Aug 26, 2020
@ansible ansible locked and limited conversation to collaborators Sep 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants