1
votes

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.

2

2 Answers

8
votes

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.

1
votes

@Miklos Kosarkar, I know this is an old post, however this was never answered. By default, Ansible ignores certain file extensions when it looks for inventory files. This is set in the [inventory] section of ansible.cfg.

[inventory]
# enable inventory plugins, default: 'host_list', 'script', 'auto', 'yaml', 'ini', 'toml'
#enable_plugins = host_list, virtualbox, yaml, constructed

# ignore these extensions when parsing a directory as inventory source
#ignore_extensions = .pyc, .pyo, .swp, .bak, ~, .rpm, .md, .txt, ~, .orig, .ini, .cfg, .retry

# ignore files matching these patterns when parsing a directory as inventory source
#ignore_patterns=

# If 'true' unparsed inventory sources become fatal errors, they are warnings otherwise.
#unparsed_is_failed=False