-1

我正在尝试在 when 语句中使用变量,并且 ansible 会弹出这样的警告

 [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ item.name}}.changed

我首先使用一个循环:

- include_tasks: anaconda_env.yml
  with_items: "{{anaconda_templates}}"

在 anaconda_env file.yml 我有这个:

- name: anaconda.templates
  template:
    owner: "{{item.owner|default(common_owner)}}"
    group: "{{item.group|default(common_group)}}"
    mode: "{{item.mode|default(common_mode)}}"
    src: "{{item.template}}"
    dest: "{{item.dest}}"
  register: "{{item.name}}"

- name: anaconda.handler
  command: echo '1' 
  notify: "{{item.name}}"
  when: "{{ item.name}}.changed"

在另一种情况下,我尝试了“{{ item.name}}.rc == 1”,但我遇到了同样的问题。知道如何避免这个 Wanring 消息。

我在这里找到了问题,但没有解决方案 https://github.com/ansible/ansible/issues/27225

4

1 回答 1

0

我最初的答案没有用,但我相信下面的答案会(或者至少用我有限的模拟数据):

- set_fact:
    current_template: "{{item}}"
- name: anaconda.handler
  command: echo '1' 
  notify: "{{item.name}}"
  when: current_template.changed is defined
于 2017-12-13T13:45:35.630 回答