-1

I am trying to use a variable in a when statement and ansible pops up a warning like this

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

I use a loop first:

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

and in the anaconda_env file.yml i have this:

- 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"

And in another situation I tried "{{ item.name}}.rc == 1" and I have the same issue. Any idea how can I avoid this Wanring message.

I found the issue here but no solution https://github.com/ansible/ansible/issues/27225

jim
  • 33
  • 4

1 Answers1

0

My original answer didn't work, but I believe the one below will (or at least did with my limited mock data):

- set_fact:
    current_template: "{{item}}"
- name: anaconda.handler
  command: echo '1' 
  notify: "{{item.name}}"
  when: current_template.changed is defined
Phil M
  • 751
  • 4
  • 6