title: ansible conditional check a item's attribute exist
body: <p>I want to create users using ansible and want to set their shell and sudo permissions.</p>
  
  <p>Now I have <code>vars/main.yml</code> as below:</p>
  
  <pre><code>users: [{'name': 'user1', 'shell': '/bin/bash', 'sudo': 'user1 ALL=(ALL) NOPASSWD: ALL'}, {'name': 'user2', 'shell': '/bin/zsh', 'sudo': 'user2 ALL=NOPASSWD:/bin/systemctl *start nginx'}, {'name': 'user3', 'shell': '/bin/fish'}]
  </code></pre>
  
  <p>On the task <code>Set sudo permission for users</code>
  because not every user have sudo permission, which I need to check if the <code>sudo</code> attribute is exist or not.</p>
  
  <pre><code>- name: Set sudo permission for users
    lineinfile:
      dest: /etc/sudoers
      state: present
      regexp: '^{{ item.name }}'
      line: "{{ item.sudo }}"
      backup: true
    when: "{{ item.sudo }}"
    with_items:
      - "{{ users }}"
  </code></pre>
  
  <p>I got error as below:</p>
  
  <pre><code>TASK [createUsers : Set sudo permission for users] ***************************
  fatal: [ubuntu]: FAILED! =&gt; {"failed": true, "msg": "The conditional check '{{ item.sudo }}' failed. The error was: expected token 'end of statement block', got 'ALL'\n  line 1\n\nThe error appears to have been in '/Users/csj/proj/roles/createUsers/tasks/main.yml': line 26, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set sudo permission for users\n  ^ here\n"}
  </code></pre>
  
  <p>I tried many about quote things but it didn't help.</p>