Browse Source

new example

master
Nicolas Massé 7 months ago
parent
commit
0f3c47b240
  1. 9
      selectattr-filter.yaml
  2. 21
      split.yaml

9
selectattr-filter.yaml

@ -32,3 +32,12 @@
vars:
output: "{{ input|selectattr('system_name', 'equalto', system_name)|list }}"
system_name: Say_Hello
- block:
- debug:
var: output
- assert:
that:
- output|length == 0
vars:
output: "{{ input|selectattr('system_name', 'equalto', system_name)|list }}"
system_name: missing

21
split.yaml

@ -0,0 +1,21 @@
- name: Split filter
hosts: localhost
gather_facts: no
tasks:
- block:
- debug:
var: output
- assert:
that:
- output | length == 4
- "output[1] | length == 4"
vars:
input:
- " Name MAC address Protocol Address"
- "-------------------------------------------------------------------------------"
- " lo 00:00:00:00:00:00 ipv4 127.0.0.1/8"
- " lo 00:00:00:00:00:00 ipv6 ::1/128"
- " enp1s0 02:02:01:00:01:66 ipv4 192.168.1.195/24"
- " enp1s0 02:02:01:00:01:66 ipv6 fe80::7ef3:9a60:321:2091/64"
output: >
{{ input[2:] | map("split", None) | community.general.json_query('[*].{"ifname": [0], "mac": [1], "proto": [2], "address": [3]}') }}
Loading…
Cancel
Save