2rs2ts
2rs2ts

Reputation: 11026

"The specified collections path is not part of the configured Ansible collections paths" but I'm installing into a relative directory

I'm installing the ansible.posix collection to use in my playbook like this:

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

However, I get this warning message that I want to get rid of:

[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.

My repo is laid out like this:

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

ansible.cfg looks like this:

[defaults]
timeout = 60
callback_whitelist = profile_tasks

Here's the output of 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]

In the docs for installing collections with ansible-galaxy, they say the following:

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>

And, like the documentation suggests, I can still use the collection just fine in my play. But this warning message is quite annoying. How do I get rid of it?

Upvotes: 4

Views: 23764

Answers (1)

aPugLife
aPugLife

Reputation: 1039

I have created ansible.cfg within the ansible project I'm working on.
You could simply cp /etc/ansible/ansible.cfg .
but since the file would look like:

[defaults]
collections_paths = ./collections/ansible_collections

It is just easier to create it.
Once there, Ansible will know about your custom configuration file.

In you project folder you will:
mkdir -p ./collections/ansible_collections
And then run the install.

If your requirements.yml contains a collection like:

collections:
  - community.general

You'd have to install it as:
ansible-galaxy collection install -r requirements.yml -p ./collections/

And the output would be:

[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'

In case you won't setup your modified ansible.cfg, the output would be:

[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'

There are other methods too, but I like this one.

Upvotes: 6

Related Questions