2

我正在安装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.

我的仓库是这样布置的:

├── 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>

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

4

1 回答 1

1

我在ansible.cfg我正在处理的 ansible 项目中创建了。
你可以简单地cp /etc/ansible/ansible.cfg .
但是因为文件看起来像:

[defaults]
collections_paths = ./collections/ansible_collections

创建它更容易。
在那里,Ansible 将了解您的自定义配置文件。

在您的项目文件夹中,您将:
mkdir -p ./collections/ansible_collections
然后运行安装。

如果您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'

如果您不设置 modified 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'

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

于 2021-05-21T22:14:24.487 回答