You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
877 B
31 lines
877 B
---
|
|
|
|
- name: Uses the "select" filter and the "search" test to filter a list
|
|
gather_facts: no
|
|
hosts: localhost
|
|
vars:
|
|
input:
|
|
# This is a sample output of the "getent ahosts openshift39.openshift.test" command
|
|
#
|
|
# - command: openshift39.openshift.test
|
|
# register: getent
|
|
#
|
|
# => this is getent.stdout_lines
|
|
#
|
|
- 192.168.23.175 STREAM openshift39.openshift.test
|
|
- 192.168.23.175 DGRAM
|
|
- 192.168.23.175 RAW
|
|
- 192.168.23.176 STREAM
|
|
- 192.168.23.176 DGRAM
|
|
- 192.168.23.176 RAW
|
|
tasks:
|
|
- block:
|
|
- debug:
|
|
var: output
|
|
- assert:
|
|
that:
|
|
- output|length == 2
|
|
- output|first == "192.168.23.175"
|
|
- output|last == "192.168.23.176"
|
|
vars:
|
|
output: '{{ input|select(''search'', ''\bSTREAM\b'')|map(''regex_replace'', ''^(\S+)\s+STREAM\b.*$'', ''\1'')|list }}'
|
|
|