how to split value in Ansible with delimiter


I am setting a fact in Ansible and that variable has a value with hyphens, like this “dos-e1-south-209334567829102380“. i want to split , so i only get “dos-e1-south”

Here is the play


another option is ansibles regular expression filter, you find here:

has the same result:

Explanation for the regex:

keep everything from the start of the string in the first backreference

find the last “-” followed by non-“-” characters till the end of string.

replaces the string with the first backreference.

Leave a Reply