Can I define my inventory in my playbook directory?

Management Node:

  • CentOs 6

  • Ansible 2.1

Remote Node:

  • Windows 7

  • Powershell 3.0

My playbooks are all saved in /home/username/playbooks.

My inventory file is saved as /etc/ansible/hosts.

And I also use the file etc/ansible/group_vars/windows.yml

I find it a hassle to go back and forth between these 2 locations. Why can’t I define my inventory and group vars in my playbooks directory? What is the best way to do that?

inventory can be anywhere you want, it just defaults to /etc/ansible/hosts, you can set in ansible.cfg or on the command line with -i switch. group/host_vars just need to be in the same directory your inventory files are.

I must be missing something. I created a ansible.cfg file with this…

[default]
hostfile = /fs01/home/janderson/hosts

and one with this…

[default]
inventory = /fs01/home/janderson/hosts

and neither one worked.

Where can I get a default or sample ansible.cfg file to modify?

We lay ours out in the playbook directory like this

site.yml
prod/
    - group_vars/
        - all
    - hosts
staging/
   - group_vars/
      - all
   - hosts

and then run with

    ansible-playbook -i $environment site.yml

This last one is almost correct, but you are missing an s it's [defaults]

Thanks Kai for pointing out my mistake!!