剧本目录和库存目录

Playbook directory and Inventory directory

Here 有一句话:

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.

如何定义:

我不知道那个配置,似乎在我玩 Ansible 的过程中,我总是有一个目录,它位于同一时间的剧本目录和库存目录中,但这种分离可能很有用。

您可以通过指向文件、脚本或目录来指定清单:

  • 在命令行中:

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

    inventory = /path/to/inventory
    

    无论您使用哪个选项,库存目录 都将是存储所用库存文件的目录。

playbook 目录 就是存储 playbook 的目录。

@Miklos Kosarkar,我知道这是一个旧的 post,但是从未有人回答过。默认情况下,Ansible 在查找清单文件时会忽略某些文件扩展名。这是在 ansible.cfg 的 [inventory] ​​部分中设置的。

[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