question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ansible filter fails when parsers have a dash in their names?

See original GitHub issue

I realise I should probably be asking this in community.general

Does the community.general.jc ansible filter simply fail for parsers with a dash in their names?

---
- name: JC test
  block:

    - name: List files in /tmp using ls -1l /tmp
      ansible.builtin.command: ls -1l /tmp
      check_mode: false
      changed_when: false
      register: jc_ls_1l

    - name: Set a fact for the result of ls -1l /tmp
      ansible.builtin.set_fact:
        jc_ls: "{{ jc_ls_1l.stdout | community.general.jc('ls') }}"

    - name: Debug list files in /tmp
      ansible.builtin.debug:
        var: jc_ls

    - name: List packages using dpkg -l
      ansible.builtin.command: dpkg -l
      environment:
        COLUMNS: 500
      check_mode: false
      changed_when: false
      register: jc_dpkg_l

    - name: Set a fact for the result of dpkg -l
      ansible.builtin.set_fact:
        jc_dpkg: "{{ jc_dpkg_l.stdout | community.general.jc('dpkg-l') }}"

  tags:
    - jc
...

Results in:

TASK [jc : List files in /tmp using ls -1l /tmp] *******************************
ok: [localhost]
TASK [jc : Set a fact for the result of ls -1l /tmp] ***************************
ok: [localhost]
TASK [jc : Debug list files in /tmp] *******************************************
ok: [localhost] => {
    "jc_ls": [
        {
            "date": "Nov 7 22:07",
            "filename": "ansible_ansible.legacy.command_payload_sn843j60",
            "flags": "drwx------",
            "group": "root",
            "links": 2,
            "owner": "root",
            "size": 4096
        }
    ]
}
TASK [jc : List packages using dpkg -l] ****************************************
ok: [localhost]
TASK [jc : Set a fact for the result of dpkg -l] *******************************
fatal: [localhost]: FAILED! => {"msg": "Error in jc filter plugin:  No module named 'jc.parsers.dpkg-l'"}

Or am I doing something daft?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chriscroomecommented, Nov 7, 2022

Good plan, I’ll leave that to you 😉 .

1reaction
kellyjonbrazilcommented, Nov 7, 2022

Yeah it probably makes sense to update the parser parameter comments on that documentation page. I think we can just submit a PR with the updated verbiage and it will go into the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using filters to manipulate data - Ansible Documentation
Filters let you transform JSON data into YAML data, split a URL to extract the hostname, get the SHA1 hash of a string,...
Read more >
hyphen in dictionary key breaks json_query #33163 - GitHub
Files identified in the description: lib/ansible/plugins/filter/json_query.py. If these files are inaccurate, please update the component name ...
Read more >
Filters — Ansible Documentation
Filters can help you manage missing or undefined variables by providing defaults or making some variable optional. If you configure Ansible to ignore...
Read more >
Ansible templating skips string after a dash - Stack Overflow
If you have VARIABLE NAMES that contain a dash, you can use vars : ... Ansible 2.8.5 seems allow dash/hyphen in the variables....
Read more >
Filter JSON Data in Ansible Using json_query | The NTC Mag
The built-in json_query filter provides the functionality for filtering, shaping, and transforming JSON data. It uses the third-party jmespath ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found