Ansible Snippets

Regular Expressions

Retrieving string between Parantheses

Given: some random text (i-want-this). Using Ansibles regex_search

- name: Just set a fact
  set_fact:
     sample: "some random text (i-want-this)"

- name: Extract between the Parantheses
  set_fact:
     what_i_want: "{{ sample | regex_search('\\(([^)]+)\\', '\\1') }}"

- name: Output the string
  debug:
    msg: what_i_want
Sean Mayhew with my Kids

Sean Mayhew

Code. Dirt. Renaissance.