title: Best Ansible layout with multiple environments
body: <p>I am utterly confused about how to manage multiple environments(prod/dev) with ansible.
  I am also using molecule to test locally.</p>
  
  <p>So here is my Project layout as of now.</p>
  
  <pre><code>|----inventories/   
  |    |   
  |    |--dev/
  |    |  |
  |    |  |--group_vars/...
  |    |  |
  |    |  |--host_vars/...
  |    |  
  |    |--prod/
  |       |
  |       |--group_vars/...
  |       |
  |       |--host_vars/
  |            |
  |            |--my_playbook_hostname_vars.yml
  |     
  |----roles/...     
  |     
  |----hosts.yml    
  |
  |----my_playbook.yml  
  |  
  </code></pre>
  
  <p>This is the directory structure according to the <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#alternative-directory-layout" rel="nofollow noreferrer">docu</a></p>
  
  <p>Now I have my molecule file where I can just link the dev directories like this</p>
  
  <pre><code># molecule.yml
  provisioner:
    name: ansible
    inventory:
      links:
        group_vars: ../../../../inventories/dev/group_vars/
        host_vars: ../../../../inventories/dev/host_vars/
  </code></pre>
  
  <p>So Molecule works just fine for local testing with a vagrant driver and I could also set it up to use a EC2 driver to test it in the cloud for example. So far so good.  </p>
  
  <p>But how do I start the my_playbook.yml? When I use <code>ansible-playbook my_playbook.yml</code> then it does not know where to look for the vars, since there are two environments. How can I tell Ansible to look under inventories/prod/group_vars &amp; inventories/prod/host_vars and then resolve further via the host and group name like it is defined in the hosts.yml without compromising my molecule setup?  </p>
  
  <p>When I just setup group_vars/ &amp; host_vars/ in the root dir it works  </p>