Can I define my inventory in my playbook directory?

34 views
Skip to first unread message

skinnedknuckles

unread,
Aug 24, 2016, 11:02:37 AM8/24/16
to Ansible Project
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?

Brian Coca

unread,
Aug 24, 2016, 11:08:18 AM8/24/16
to ansible...@googlegroups.com
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.


----------
Brian Coca

skinnedknuckles

unread,
Aug 31, 2016, 1:13:23 PM8/31/16
to Ansible Project
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?

Dick Davies

unread,
Aug 31, 2016, 1:29:25 PM8/31/16
to ansible list
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


On 24 August 2016 at 16:02, skinnedknuckles
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/60334eae-42fb-4154-b65f-a5090313c8f7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Aug 31, 2016, 2:22:54 PM8/31/16
to ansible...@googlegroups.com
On 31. aug. 2016 19:13, skinnedknuckles wrote:
> 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

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

--
Kai Stian Olstad

skinnedknuckles

unread,
Aug 31, 2016, 2:42:02 PM8/31/16
to Ansible Project
Thanks Kai for pointing out my mistake!!


On Wednesday, August 24, 2016 at 10:02:37 AM UTC-5, skinnedknuckles wrote:
Reply all
Reply to author
Forward
0 new messages