"The specified collections path is not part of the configured Ansible collections paths"但我正在安装到相对目录



我正在安装ansible.posix集合,以便在我的剧本中使用:

ansible-galaxy collection install -r ansible/requirements.yml -p ansible/collections

然而,我得到这个警告消息,我想摆脱:

[WARNING]: The specified collections path '/home/myuser/path/to/my/repo/ansible/collections' is not part of the
configured Ansible collections paths '/home/myuser/.ansible/collections:/usr/share/ansible/collections'. The installed collection won't be
picked up in an Ansible run.

我的repo是这样布局的:

├── ansible
│   ├── playbook.yml
│   ├── files
│   │   ├── ...
│   ├── tasks
│   │   ├── ...
│   ├── requirements.yml
├── ansible.cfg
...

ansible.cfg看起来像这样:

[defaults]
timeout = 60
callback_whitelist = profile_tasks

ansible --version的输出:

ansible 2.9.17
config file = /home/myuser/path/to/my/repo/ansible.cfg
configured module search path = ['/home/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]

在使用ansible-galaxy安装集合的文档中,他们这样说:

你也可以在collections/ansible_collections/目录结构下,在当前剧本附近保存一个集合。

play.yml
├── collections/
│   └── ansible_collections/
│               └── my_namespace/
│                   └── my_collection/<collection structure lives here>

并且,正如文档所示,我仍然可以在我的游戏中很好地使用集合。但是这个警告信息很烦人。我如何摆脱它?

我在可行的项目中创建了ansible.cfg
您可以简单地cp /etc/ansible/ansible.cfg .
,但由于文件看起来像:

[defaults]
collections_paths = ./collections/ansible_collections

创建它更容易。
一旦存在,Ansible就会知道你的自定义配置文件。

在你的项目文件夹中:
mkdir -p ./collections/ansible_collections
然后运行install.

如果您的requirements.yml包含如下集合:

collections:
- community.general

ansible-galaxy collection install -r requirements.yml -p ./collections/

输出将是:

[borat@mypotatopc mycoolproject]$ ansible-galaxy collection install -r requirements.yml -p ./collections/
Process install dependency map
Starting collection install process
Installing 'community.general:3.1.0' to '/home/borat/projects/mycoolproject/collections/ansible_collections/community/general'

如果您不设置修改后的ansible.cfg,输出将是:

[borat@mypotatopc mycoolproject]$ ansible-galaxy collection install -r requirements.yml -p ./
[WARNING]: The specified collections path '/home/borat/projects/mycoolproject' is not part of the configured Ansible collections paths
'/home/borat/.ansible/collections:/usr/share/ansible/collections'. The installed collection won't be picked up in an Ansible run.
Process install dependency map
Starting collection install process
Installing 'community.general:3.1.0' to '/home/borat/projects/mycoolproject/ansible_collections/community/general'

还有其他方法,但我喜欢这个。

相关内容

  • 没有找到相关文章

最新更新