繁体   English   中英

Ansible - Jinja2 导入模板遇到未定义的变量

[英]Ansible - Jinja2 template with import encounters undefined variable

我的剧本调用以下任务:

name: Mytask
    template:
       src: "path/to/template.j2"
       dest: "/dest/file"
       mode: '755'

这个模板使用变量 {{ organization }} 然后导入一个带有上下文关键字的神社宏

{% 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 %}

最后是导入的 jinja 宏,这里我在尝试打印时得到一个未定义的变量 {{ organization }}

{% macro function_name(param1, param2) %}
{{ organization|pprint }}
{% endmacro %}

该变量在传递给第一个模板时定义,但它不遵循该模板内的导入,与上下文包含相同的问题。

我在版本 2.9.21 和 Python 2.7.12 中运行 ansible(对于与 python 3 不兼容的库,需要 python 2.7)

升级python和ansible后解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM