From 0f3c47b240be6329de818a4c757040b7d1025b0a Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Sun, 27 Apr 2025 21:21:05 +0200 Subject: [PATCH] new example --- selectattr-filter.yaml | 9 +++++++++ split.yaml | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 split.yaml diff --git a/selectattr-filter.yaml b/selectattr-filter.yaml index e952c5b..a8a3184 100644 --- a/selectattr-filter.yaml +++ b/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 diff --git a/split.yaml b/split.yaml new file mode 100644 index 0000000..b968fed --- /dev/null +++ b/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]}') }}