'Ansible - Jinja2 template with import encounters undefined variable
My playbook calls the following task :
name: Mytask
template:
src: "path/to/template.j2"
dest: "/dest/file"
mode: '755'
This template uses the variable {{ organization }} then import a jinja macro with the keyword with context
{% for organization in organization _list %}
- name: Loading
include_vars:
file: "{{ config_file_dir }}/{{ organization }}/{{ file_name }}"
name: "platform_file"
{% from 'another_template.j2' import function_name as name with context %}
{{ name(param1, param2) }}
{% endfor %}
and finally the imported jinja macro, here I get an undefined variable {{ organization }} when trying to print it.
{% macro function_name(param1, param2) %}
{{ organization|pprint }}
{% endmacro %}
The variable is defined when passed to the first template but it doesn't follow the import inside that template, same issue for an include with context.
I am running ansible in version 2.9.21 and Python 2.7.12 (need python 2.7 for a library incompatible with python 3)
Solution 1:[1]
Solved after upgrading python and ansible
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 |
