title: Ansible include vars per host
body: <p>I've got a problem with Ansible 2.2 in Ubuntu.</p>
  
  <p>My playbook contains the following:</p>
  
  <pre><code>---
  - hosts: all
    become: yes
    roles:
      - mysql
  </code></pre>
  
  <p>I've used the MySQL role from here <a href="https://galaxy.ansible.com/geerlingguy/" rel="nofollow noreferrer">https://galaxy.ansible.com/geerlingguy/</a> but renamed all to <code>MySQL</code> locally. In the defaults folder of the playbook is a file which contains the parameter:</p>
  
  <pre><code>mysql_datadir: /var/lib/mysql
  </code></pre>
  
  <p>With that, Ansible is working fine. But now I want a specific configuration per host as explained here: <a href="http://docs.ansible.com/ansible/playbooks_best_practices.html" rel="nofollow noreferrer">http://docs.ansible.com/ansible/playbooks_best_practices.html</a></p>
  
  <p>So I created the file <code>inventories/host_vars/test.yml</code>, removed the one in the defaults folder of the task and updated the playbook to the following:</p>
  
  <pre><code>  ---
  - hosts: all
    become: yes
    roles:
      - mysql
    tasks:
    - name: include vars
      include_vars: inventories/host_vars/test.yml
  </code></pre>
  
  <p>Now Ansible won't accept that; it says that the variable is not set:</p>
  
  <blockquote>
    <p>fatal: []: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'mysql_datadir' is undefined\n\nThe error appears to have been in '/home/michael/Ansible/Playbooks/roles/mysql/tasks/setup-Debian.yml': line 24, 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: Delete innodb log files created by apt package after initial install.\n  ^ here\n"}</p>
  </blockquote>
  
  <p>Passing the argument via command line works without problems. How can I fix that?</p>