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