title: Ansible condition to run specific tasks in a playbook only if host belongs to specific group in inventory file
body: <p>I created a playbook with 6 different tasks and want to run tasks 1,2,3 only when host is a child of <code>was855node</code> group (e.g. <code>b</code>, <code>c</code>) and tasks 4,5 to run only when hosts is child of <code>was855dmgr</code> group (e.g. <code>a</code>)</p>
  
  <p>My inventory file:</p>
  
  <pre><code>[local-linux:children]
  was855
  
  [was855:children]
  was855dmgr
  was855node
  
  [was855dmgr:children]
  hppidc-pps-dmgr
  hppndc-pps-dmgr
  hppb-pps-dmgr
  
  **hreg1-mnp-dmgr**
  
  [was855node:children]
  wppdev3-pps-node
  hint1-pps-node
  
  **hreg1-mnp-node**
  
  [hreg1-mnp-dmgr]
  a 
  
  [hreg1-mnp-node]
  b 
  c 
  </code></pre>
  
  <p>is this the correct way to do it?</p>
  
  <pre><code>- name: Run create-app-logs.py on the Nodes ***(i want to run it on a ONLY)***
    shell: "{{ was_profile_path }}/bin/wsadmin.sh -lang jython -f {{ build_scripts_dir }}/create-app-logs.py"
    register: r
    when: "'was855dmgr' in group_names"
    tags: create_app_logs
  
  - name: Create shared libraries directory ***(i want to run it on b and c ONLY)***
    file: path={{ was_shared_lib_location }} state=directory owner=wasadm group=apps mode=0755
    when: "'was855node' in group_names"
  </code></pre>