title: Trying to split my Ansible playbook based on the Operating System
body: <p>I have a playbook which needs to be run based on the operating System.
  UseCase: Lets assume there is a service that is running. </p>
  
  <p>On Linux we can check if it is installed and running using the 
  systemctl status application.service</p>
  
  <p>While command and on windows we will be using the 
  sc query "ServiceName" | find "RUNNING"</p>
  
  <p>Now we have to install it based on the output of the above a commands which requires us to segregate the playbook based on the OS.</p>
  
  <p>Classic Example: Create a directory based on the OS</p>
  
  <pre><code>- name: Install QCA Agent on Linux targets
    hosts: all
    gather_facts: true
    remote_user: root
    tasks:
  
  - name: Create Directory for Downloading Qualys Cloud Agent
    sudo: yes
    sudo_user: root
    file:
      path: /usr/q1/
      state: directory
      owner: root
      group: root
      mode: 0777
      recurse: no
  - name: Create Directory for Downloading Qualys Cloud Agent
    win_file:
      path: c:\q1
      state: directory
      owner: Administrator
      group: Administrator
      mode: 0777
      recurse: no
  </code></pre>
  
  <p>The playbook will alwayz be successful only if one of the condition is met and it is whether it is Windows or Unix OS. I can alwayz add a condition which will prompt based on:</p>
  
  <pre><code>when: ansible_distribution == 'Redhat' or ansible_distribution == 'CentOS'
  </code></pre>
  
  <p>However what i would like to achieve is based on a condition it should trigger my playbook.yml file. </p>
  
  <pre><code> name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file.
    include_vars: "{{ item }}"
    with_first_found:
      - "{{ ansible_distribution }}.yaml"
      - "{{ ansible_os_family }}.yaml"
      - default.yaml
  
  https://docs.ansible.com/ansible/2.5/modules/include_vars_module.html?highlight=with_first_found
  </code></pre>
  
  <p>I would like to know if there is a better example explaining the same that i could implement or if there are other ways to achieve the same.</p>
  
  <p>Thank you,</p>