我正在尝试从 Ansible 文档站点最佳实践部分创建替代目录布局。
按照这个指导,这是我在里面创建的布局~/ansible_proj/windows_setup
(windows_setup
是一个 Python 虚拟环境):
.venv
inventories/
production/
hosts
group_vars/
windows
windows.yml
vault
windows_configure.yml
roles/
role1/
role2/
role3/
role4/
.gitignore # this contains 1 line produced by: echo 'vault' >> .gitignore
当我尝试运行 playbook时,按照此处windows_configure.yml
的建议(参见第一个示例),使用
$ (.venv) cd ~/ansible_proj/windows_setup
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i production windows_configure.yml --ask-vault-pass
错误是
Unable to parse /.../production as an inventory source
production hosts list is empty, only localhost is available
我必须指出hosts
文件的路径,而不是像:
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i inventories/production/hosts windows_configure.yml --ask-vault-pass
为了让它运行。
Q1。如何使用替代目录布局通过使用production
(如文档建议)而不是运行剧本inventories/production/hosts
?
在相同的目录结构中,如果我放在windows_configure.yml
里面playbooks/
,并运行:
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i inventories/production/hosts playbooks/windows_configure.yml
--ask-vault-pass
然后我得到这个错误
ERROR: the role 'role1' was not found in /.../playbooks/roles:/.../playbooks
Q2。在这个替代目录结构中,是否可以将所有剧本放在一个playbooks
目录中?
编辑
我尝试添加ansible.cfg
到当前目录(~/ansible_proj/windows_setup
)(其中还包含剧本windows_configure.yml
。这里是ansible.cfg
:
[defaults]
inventory = ~/ansible_proj/windows_setup/inventories/production
roles_path = ~/ansible_proj/windows_setup
当我跑
$ (.venv) cd ~/ansible_proj/windows_setup
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i production windows_configure.yml --ask-vault-pass
出现同样的错误
Unable to parse /.../production as an inventory source
production hosts list is empty, only localhost is available