Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto extract last number in ansible variable

Tags:

regex

ansible

I have variable, its version numbering. How I catch last number in version

example

app_ver: 1.5.0.0.20

- debug:
    var: app_ver | regex_search('^(\d+).(\d+).(\d+).(\d+).(\d+)$') | list

gives me

"app_ver |regex_search('^(\\d+).(\\d+).(\\d+).(\\d+).(\\d+)$') | list": [
        "1",
        ".",
        "5",
        ".",
        "0",
        ".",
        "0",
        ".",
        "2",
        "0"
    ]

I need last number, may be 1-figure or more

like image 534
Indrek Mäestu Avatar asked Dec 11 '25 14:12

Indrek Mäestu


1 Answers

Split the line by . and take last element:

- debug:
    msg: "{{ app_ver.split('.')[-1] }}"
like image 67
Konstantin Suvorov Avatar answered Dec 14 '25 04:12

Konstantin Suvorov