itiic
itiic

Reputation: 3712

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:

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.

Upvotes: 2

Views: 22806

Answers (2)

jlagermann
jlagermann

Reputation: 101

@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

Upvotes: 4

techraf
techraf

Reputation: 68439

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.

Upvotes: 9

Related Questions