Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Created April 9, 2020 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssbarnea/2612f4fff99443fe934412bd34e36cb9 to your computer and use it in GitHub Desktop.
Save ssbarnea/2612f4fff99443fe934412bd34e36cb9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ansible-playbook
- hosts: localhost
gather_facts: no
tasks:
- vars:
data:
system:
df:
cmd: df -a
mem:
cmd: mem
hw:
pci:
cmd: lspci
debug:
msg: |
{{ data | json_query('*.*') }}
# TODO: category (system, hw) must be also added to each dictionary
# TODO: command name (2nd dic key), must be also added to each dicitonary
# TODO: flatten the nested list
# Current output:
# "msg": [
# [
# {
# "cmd": "df -a"
# },
# {
# "cmd": "mem"
# }
# ],
# [
# {
# "cmd": "lspci"
# }
# ]
# ]
# Desired output:
# - cmd: "df-a"
# group: system
# name: df
# ...
# Resources:
# https://jmespath.org/tutorial.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment