title: How to use host variables in when condition in ansible playbook
body: <p>I am trying to execute my task only when the host name has the variable <code>servers=admin</code>.</p>
  <p>I am trying to execute the below playbook but I am facing an error.<br />
  I am trying this because it is similar to something which works for me like <code>inventory_hostname in groups['production']</code>. I would like to run the task only when the server variable has <code>admin</code> in it.</p>
  <p>My host file:</p>
  <pre><code>[production]
  host1 servers=admin,server1
  host2 servers=server2
  host3 servers=admin,server3
  host4 servers=server4
  host5 servers=server5
  host6 servers=admin,server6
  </code></pre>
  <p>My task:</p>
  <pre class="lang-yaml prettyprint-override"><code>- name: run cmd
    shell: hostname
    register: op
    when:
      - inventory_hostvars in servers['admin']
  </code></pre>
  <p>My task should run only on <code>host1</code>, <code>host3</code> and <code>host6</code>.</p>