Home > Software engineering >  How to modify variable inside ansible jinja2 template
How to modify variable inside ansible jinja2 template

Time:03-17

I am passing a variable called x_version=v5.5.9.1 to the Ansible jinja2 template(bash). But inside the receiving bash script (jinja2) variable x_version should be modified to v5.5.9.

version_defined_in_ansible={{ x_version }}

CodePudding user response:

Below modification helped me.

version_defined_in_ansible=v{{ x_version.split('v')[1][0:5] }}

CodePudding user response:

Given the variable

x_version: v5.5.9.1

The simplest approach is to split the extension

{{ x_version|splitext|first }}

evaluates to

v5.5.9
  • Related