Skip to content

Instantly share code, notes, and snippets.

View DrPsychick's full-sized avatar
🤔

DrPsychick DrPsychick

🤔
View GitHub Profile
@DrPsychick
DrPsychick / gist:4a1faa089c4bda04f1365adfdd599bac
Created September 2, 2018 13:52
nested dict with lists filtering example
"ansible_influx_mm_backfill.results|map(attribute='json.results')|flatten|map(attribute='series')|flatten|list": [
{
"columns": [
"time",
"written"
],
"name": "result",
"values": [
[
"1970-01-01T00:00:00Z",
@DrPsychick
DrPsychick / gist:12cbee2b36c82ef8441ef00af47fcadf
Last active September 2, 2018 01:24
ansible dict filter with attribute name same as built-in method
# 'values' is a built-in method and therefore always exists. This is especially useful for "influxDB" API output from an uri command.
# test attribute type with selectattr('fieldname', TEST), see http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-tests
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |selectattr('values', 'string') |map(attribute='values') |list }}"
# alternatively filter:
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |rejectattr('values', 'callable') |map(attribute='values') |list }}"