#ansible #regexp quick test

Hi there, trying some regexps in ansible running roles is annoying. Then I using the following trick thru the command line to test my regexp.

Next example, I am trying to remove last component from the IP Address ‘10.10.10.2’ and trub that into ‘10.10.10.0’

ansible all -i 'localhost,' -c local -m command -a "echo {{ '10.10.10.2' | regex_replace('^([0-9]*\.[0-9]*\.[0-9]*)\.[0-9]*$', '\\1\.0') }}"
localhost | SUCCESS | rc=0 >>
10.10.10.0

See ya!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s