https://github.com/moreati/jq-filter
Ansible filter plugin for jq filter expressions
https://github.com/moreati/jq-filter
ansible ansible-collection ansible-filter jq
Last synced: 6 months ago
JSON representation
Ansible filter plugin for jq filter expressions
- Host: GitHub
- URL: https://github.com/moreati/jq-filter
- Owner: moreati
- Created: 2019-02-07T00:13:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T20:37:25.000Z (about 1 year ago)
- Last Synced: 2025-04-05T00:35:21.235Z (6 months ago)
- Topics: ansible, ansible-collection, ansible-filter, jq
- Language: Python
- Homepage: https://galaxy.ansible.com/moreati/jq
- Size: 10.7 KB
- Stars: 22
- Watchers: 4
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jq-filter
=========This Ansible collection provides `jq()`, a filter that slices and dices JSON
just like the [jq] command. It's particularly good with deeply nested lists
of dicts, and dicts of lists.Example
-------A list of databases & nested users such as
```yaml
databases:
- {name: db1, users: [{username: alice}, {username: alex}]}
- {name: db2, users: [{username: bob}, {username: brienne}]}
```can be transformed by a template expression such as
```jinja
{{ databases | moreati.jq.jq('map({db: .name, user: .users[].username}) }}```
into a flat list
```
[
{"db": "db1", "user": "alice"},
{"db": "db1", "user": "alex"},
{"db": "db2", "user": "bob"},
{"db": "db2", "user": "brienne"}
]
```You can try out jq expressions at [jqplay.org], starting with this [example].
[jq]: https://stedolan.github.io/jq/
[jq expression language]: https://stedolan.github.io/jq/manual/#Basicfilters
[jqplay.org]: https://jqplay.org
[example]: https://jqplay.org/s/zg_l3ZoT6CInstallation
------------To install this collection run
```
ansible-galaxy collection install moreati.jq
```Requirements
------------This collection requires
- [Ansible] >= 2.8
- [Python jq] >= 1.0To install Python jq run
```
python -m pip jq
```Python jq is only needed on the Ansible controller (the host your playbooks
run _from_). It's not needed on Ansible targets (hosts your playbooks run
_against_). The `jq` command isn't needed.pre-compiled wheels have been published for CPython 2.7, and 3.x on MacOS,
and Linux (x86, x86_64). Other Python version, and pltforms will need to build
the module from source.[ansible]: https://ansible.com
[Python jq]: https://pypi.org/project/jqRole Variables
--------------None.
Dependencies
------------No dependencies on other roles.
Example Playbook
----------------- [playbooks/demo.yml]
[playbooks/demo.yml]: https://github.com/moreati/jq-filter/blob/master/playbooks/demo.yml
License
-------Apache 2.0