【问题标题】:Why does my ansible template file have no substitutions?为什么我的 ansible 模板文件没有替换?
【发布时间】:2022-11-04 05:32:56
【问题描述】:

我有一个 Ansible 模板文件,我正在使用“模板”指令正确应用它,但它显示在远程机器上,没有替换:

- name: "buildAgent.properties for {{ agent_name }}"
  template:
    src: buildAgent.properties.j2
    dest: "{{ config_path }}/buildAgent.properties"

模板文件如下所示:

serverUrl={{ teamcity_url }}
name={{ agent_name }}

{% if teamcity_agent_variables %}
{% for variable in teamcity_agent_variables %}
{{ variable }}={{ teamcity_agent_variables[variable] }}
{% endfor %}
{% else %}
# no teamcity_agent_variables from ansible
{% endif %}

当它到达远程机器时,没有来自ansible的错误,它看起来完全一样 - 即使当我在模板步骤之前的步骤中显示变量时,它们也存在

【问题讨论】:

    标签: ansible jinja2


    【解决方案1】:

    事实证明,teamcity_agent_variables 在一个文件中被列表而不是哈希覆盖,因此尝试尊重它失败了。

    我不知道为什么 Ansible 在 jinja 失败时没有打印有用的错误,而不是简单地复制模板。

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 2018-02-06
      • 1970-01-01
      • 2020-09-02
      • 2013-07-10
      • 1970-01-01
      • 2020-01-08
      • 1970-01-01
      相关资源
      最近更新 更多