'How to modify variable inside ansible jinja2 template
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 }}
Solution 1:[1]
Below modification helped me.
version_defined_in_ansible=v{{ x_version.split('v')[1][0:5] }}
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anto |
| Solution 2 | Vladimir Botka |
