Skip to content

Instantly share code, notes, and snippets.

@nmartins0611
Created August 22, 2023 09:23
Show Gist options
  • Save nmartins0611/6554b586bdbd780ff7dd9002ebf215f9 to your computer and use it in GitHub Desktop.
Save nmartins0611/6554b586bdbd780ff7dd9002ebf215f9 to your computer and use it in GitHub Desktop.
Regex Filter playbook to process patterns for hostnames
##example
---
- name: Regex Processing for hostnames
hosts: localhost
connection: local
gather_facts: false
vars:
eda_input: "{{ ansible_eda.event.payload.text }}" # access event payload
regex_pattern: '\b(\w+\.mydomain\.com)\b' # can supply via vars.yml
tasks:
- name: Extract switch name from text
set_fact:
cacheable: yes
switch_devices: "{{ eda_input | regex_findall(regex_pattern) }}"
regex_proc: done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment