title: Ansible variable defined in group_vars/all not found
body: <p>Assume the Ansible structure:</p>
  
  <pre><code>.
  ├── group_vars
  │   └── all
  └── site.yml
  </code></pre>
  
  <p>Where <code>all</code> contains <code>my_test_variable: yes</code>, and <code>site.yml</code> is:</p>
  
  <pre><code>- hosts: all
  
    tasks:
      - name: Variable test
        debug: msg={{ my_test_variable }}
  </code></pre>
  
  <p>I'm using Vagrant to run it locally, so the command looks like:</p>
  
  <p><code>$ ansible-playbook site.yml -i /path-to-vagrant/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=/path-to-vagrant/.vagrant/machines/default/virtualbox/private_key -u vagrant</code></p>
  
  <p>Vagrant's generated invertory file:</p>
  
  <pre><code># Generated by Vagrant
  
  default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
  </code></pre>
  
  <p>And the output:</p>
  
  <pre><code>PLAY: ***************************************************************************
  
  TASK [setup] ********************************************************************
  ok: [default]
  
  TASK [Variable test] ************************************************************
  fatal: [default]: FAILED! =&gt; {"msg": "ERROR! the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'my_test_variable' is undefined", "failed": true}
  
  PLAY RECAP **********************************************************************
  default                    : ok=1    changed=0    unreachable=0    failed=1 
  </code></pre>
  
  <p>I know this vagrant inventory is not inside any group - because there isn't any - but all groups inherit from <strong>all</strong>, right?</p>
  
  <p>Why doesn't it work? What did I miss?</p>
  
  <hr>
  
  <p>I'm Quite new to Ansible. Read a lot of the docs, couple of examples and even some SO questions like <a href="https://stackoverflow.com/questions/23767765/ansible-doesnt-pick-up-group-vars-without-loading-it-manually">Ansible doesn&#39;t pick up group_vars without loading it manually</a> -- not quite my problem -- and <a href="https://stackoverflow.com/questions/31075868/cannot-get-ansible-to-recognize-group-variables">Cannot get ansible to recognize group variables</a> -- close but not there either.</p>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>I'm following the recommended project structure from <a href="http://docs.ansible.com/playbooks_best_practices.html#directory-layout" rel="noreferrer">Ansible's doc</a>, and in the <a href="https://docs.ansible.com/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable" rel="noreferrer">variables doc entry</a> they mention the <strong>global_vars/all</strong>:</p>
  
  <blockquote>
    <p>Site wide defaults should be defined as a ‘group_vars/all’ setting. </p>
  </blockquote>
  
  <p>Even though there is no direct reference on how to load these default values, I assume I don't have to explicitly add them (like suggested in the answer by @thiago-borges). Or do I?</p>
  
  <p>The reason for this is that I intend to have group vars inheriting from <strong>all</strong>, like:</p>
  
  <pre><code>.
  ├── group_vars
  │   └── all
  │   └── production
  │   └── staging
  └── site.yml
  </code></pre>
  
  <p>And when I execute ansible-playbook for each, different files are loaded without I having to explicitly set them in the play file, eg:</p>
  
  <p><code>ansible-playbook -i production site.yml</code></p>
  
  <hr>
  
  <h2>Edit 2</h2>
  
  <p>The issue was a bug on ansible. After an update it worked as documented.</p>
  
  <p>Should I delete this question then?</p>