Jinja convert string to integer

Question:

I am trying to convert a string that has been parsed using a regex into a number so I can multiply it, using Jinja2. This file is a template to be used within an ansible script.

I have a series of items which all take the form of <word><number> such as aaa01, aaa141, bbb05.

The idea was to parse the word and number(ignoring leading zeros) and use them later in the template.

I wanted to manipulate the number by multiplication and use it. Below is what I have done so far
`

Answer:

You need to cast string to int after regex’ing number:

And then there is no need in | int inside get_host_range macro.

Leave a Reply