Skip to content

Instantly share code, notes, and snippets.

@restump
Last active August 10, 2023 08:39
Show Gist options
  • Save restump/c22b361a3127c61f9d4970254b367c1f to your computer and use it in GitHub Desktop.
Save restump/c22b361a3127c61f9d4970254b367c1f to your computer and use it in GitHub Desktop.
Example demonstrating string extraction from HTML content in Ansible with regex_search filter plugin
---
- hosts: localhost
connection: local
tasks:
- uri:
url: https://rstumph2.service-now.com/stats.do
return_content: yes
register: response
- debug: msg="{{ response.content }}"
- set_fact: "mid_build_stamp={{ response.content | regex_search('MID buildstamp: ([^<]{1,})') }}"
- debug: "msg={{ mid_build_stamp.split(': ')[1]}}"
@optica-phoffmann
Copy link

Just in case someones stumbles across this from google, like I did. There is no need to use intermediate set_fact.

  - debug: msg="{{ response.content }}"
 
  - debug: "msg={{ (response.content | regex_search('MID buildstamp: ([^<]{1,})')).split(': ')[1] }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment