#ansible (2020-10)

ansible

Discussions related to ansible configuration management

2020-10-19

Brij S avatar

Hey guys, I can’t seem to get regex_replace to work with the following: account_type: "{{ caller_info.account_alias| regex_replace('([a-z]*$)/', '\\1') }}"

For example, caller_info.account_alias =org-dig-sandbox-nonprod account_type should return nonprod

The regex seems to work on regex101 online am I missing anything

stackoverflow1
Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

I think what you want is:

account_type: "{{ caller_info.account_alias| regex_replace('^.*?-([a-z]+$)/', '\\1') }}"
Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

otherwise you’re just replace the capture group with itself

2020-10-26

    keyboard_arrow_up