unnecessary to use '{{' in conditionals...except when it isn't

130 views
Skip to first unread message

Shawn Ferry

unread,
Apr 22, 2015, 6:28:43 PM4/22/15
to ansible...@googlegroups.com
 [WARNING]: It is unnecessary to use '{{' in conditionals, leave variables in loop expressions bare.

I'm using with_items for conditions in the fail module and it seems that I can't use bare expressions.  I have a playbook that with actions that can only run if a number of pre-conditions have been met. Instead of defining N tasks to grep in a file I'm stashing the contents of the file and using multiple search conditions. 

Is there a different/better way to do this type of testing? 
Is there some way to do this without dereferenceing

---
- hosts: 127.0.0.1
  vars:
    truthy_string: This message contains the truth
  connection: local
  tasks:
    - name: test
      fail:
        msg: "{{ item.msg }}"
      with_items: 
        - { test: True != True, msg: The truth is still truthy }
        - { test: True != False, msg: The truth is out there }
        # Indicative of the actual statements I'm using
        - { test: truthy_string | search('the truth') == False, msg: It is true}
      # Dereferenced variables work but present a warning
      when: "{{ item.test }}"
      # Bare variables fail every time
      #when: item.test


--
Shawn

Brian Coca

unread,
Apr 22, 2015, 6:30:28 PM4/22/15
to ansible...@googlegroups.com
item.test is not a bare variable, in any case the warning has been
removed in newer versions of ansible.


--
Brian Coca

Tomasz Kontusz

unread,
Apr 23, 2015, 2:48:07 AM4/23/15
to ansible...@googlegroups.com
The brackets are, in fact, necessary. The effect your see is a known problem with a feature called "bare variable detection" - it never worked well, and probably never will (it's a problem since at least 1.6).

Shawn Ferry <sfe...@gmail.com> napisał:

--
Wysłane za pomocą K-9 Mail.
Reply all
Reply to author
Forward
0 new messages