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

filetree_create should output yamllint compatible truthy values #796

Closed
kbreit-insight opened this issue Mar 22, 2024 · 3 comments · Fixed by #797
Closed

filetree_create should output yamllint compatible truthy values #796

kbreit-insight opened this issue Mar 22, 2024 · 3 comments · Fixed by #797
Labels
bug Something isn't working

Comments

@kbreit-insight
Copy link

Summary

I use the filetree_create role to extract the configuration to assist in creating data structures. Unfortunately, the output of boolean values is True or False. When I run ansible-lint or yamllint it says these are incorrect truthy values since it prefers lowercase.

Issue Type

  • Bug Report

Desired Behavior

The output should be valid YAML, at least related to truthiness.

@kbreit-insight kbreit-insight added bug Something isn't working new New issue, this should be removed once reviewed labels Mar 22, 2024
@djdanielsson
Copy link
Collaborator

you could just change your lint rules to allow for True/False those yamllint rules are not default

@djdanielsson djdanielsson removed the new New issue, this should be removed once reviewed label Mar 22, 2024
@ivarmu
Copy link
Contributor

ivarmu commented Mar 25, 2024

Hi @kbreit-insight. The filetree_create role is using the filter bool (see https://docs.ansible.com/ansible/latest/collections/ansible/builtin/bool_filter.html) to generate the boolean values. If there's any requirement to have that values in lowercase, I'd propose to just run some commands using sed to translate them to your needs.

@ivarmu
Copy link
Contributor

ivarmu commented Mar 25, 2024

I've seen an incoherent behaviour when running the bool filter:

$ cat /tmp/test.yaml             
---
- hosts: localhost
  connection: local
  vars:
    testvar: 0
  tasks:
    - debug:
        msg:
          - "{{ testvar | bool }}"
          - "{{ testvar | bool | lower }}"
    - template:
        src: /tmp/test.j2
        dest: /tmp/test.out
...
$ cat /tmp/test.j2               
{{ testvar | bool }}
{{ testvar | bool | lower }}
$ ansible-playbook /tmp/test.yaml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *********************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        false,
        "false"
    ]
}

TASK [template] ******************************************************************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

$ cat /tmp/test.out             
False
false
$

So... it's only written down capitalized when is used into a template (not while in debug)... It should be no such an effort modifying the templates to generate lowercase outputs... I'm working on it, as it seems more consistent with the Ansible Truthy values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants