Search code examples
ansibleansible-inventory

Playbook directory and Inventory directory


Here there is a sentence:

Tip: In Ansible 1.2 or later the group_vars/ and host_vars/ directories can exist in the playbook directory OR the inventory directory. If both paths exist, variables in the playbook directory will override variables set in the inventory directory.

How can I define:

  • playbook directory
  • inventory directory

I'm not aware of that configuration and it seems that in my plays with Ansible I always have one dir which was in the same time playbook directory and inventory directory, but such separation could be useful.


Solution

  • You can specify the inventory by pointing to either a file, a script, or a directory:

    • in command-line:

      ansible-playbook playbook.yml -i /path/to/inventory
      
    • in ansible.cfg:

      inventory = /path/to/inventory
      

      Regardless of which option you use the inventory directory will be the one in which the used inventory file is stored.

    And the playbook directory is simply the one in which the playbook is stored.