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

标签 ansible ansible-2.x ansible-galaxy

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

the docs for installing collections with ansible-galaxy ,他们说:

You can also keep a collection adjacent to the current playbook, under a collections/ansible_collections/ directory structure.

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

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

最佳答案

我在我正在处理的 ansible 项目中创建了 ansible.cfg
你可以简单地 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'

如果您不设置修改后的 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'

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

关于ansible - "The specified collections path is not part of the configured Ansible collections paths"但我正在安装到相对目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65944341/

相关文章:

mysql - Ansible 原始和引用

python - 如何从 Ansible 中的组中获取包含特定字符串的主机名

ansible - 模板模块可以处理多个模板/目录吗?

amazon-web-services - 无法使用ansible删除AWS中的路由表

ansible - 在ansible中将ssl证书从服务器复制到主机

ansible - 有没有办法覆盖定义到 ansible Galaxy 角色中的模板?

ansible - 如何在 Ansible 中的多个任务之间共享参数

带有条件的 Ansible ad-hoc 命令

amazon-ec2 - ansible 获取已经存在的 aws ebs 卷 ID

git - 在 Jenkins 作业中使用 ansible-galaxy 的凭证和私有(private) gitlab 仓库