title: Only run Ansible task on box in specific group
body: <p>I am trying to create a task that will only run on a box that is in a specific group (called <code>pi</code>).</p>
  
  <p>I am using Ansible version:</p>
  
  <pre><code>ansible 2.3.2.0
    config file = /Users/user/Development/raspbian-homeassistant/ansible.cfg
    configured module search path = Default w/o overrides
    python version = 3.6.3 (default, Dec  3 2017, 10:37:53) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
  </code></pre>
  
  <p>This is my current code:</p>
  
  <pre><code>- name: Set up zwave USB dongle
    when: inventory_hostname in groups['pi']
    blockinfile:
      path: /var/local/homeassistant/.homeassistant/configuration.yaml
      marker: "# {mark} ANSIBLE MANAGED BLOCK #"
      insertafter: "# zwave dongle"
      content: |2
        zwave:
          usb_path: /dev/ttyACM0
    tags:
      - config
      - hass
  </code></pre>
  
  <p>It seems to work correctly when the hostname is in the group but throws an error when not.</p>
  
  <p>This is the error I get when I run it on my vagrant box (in group <code>vagrant</code>):</p>
  
  <pre><code>fatal: [192.168.33.123]: FAILED! =&gt; {"failed": true, "msg": "The conditional check 'inventory_hostname in groups['pi']' failed. The error was: error while evaluating conditional (inventory_hostname in groups['pi']): Unable to look up a name or access an attribute in template string ({% if inventory_hostname in groups['pi'] %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like '-': argument of type 'StrictUndefined' is not iterable\n\nThe error appears to have been in '/Users/andy/Development/raspbian-homeassistant/ansible/roles/configure-hass/tasks/main.yml': line 21, 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 up zwave USB dongle\n  ^ here\n"}
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/28080145/check-if-a-list-contains-an-item-in-ansible">Check if a list contains an item in Ansible</a> suggests I have the syntax right but I guess that is for an older version of Ansible?</p>
  
  <p>How do I fix this?</p>