Ansible collections are modular packages that group related content such as roles, modules, and plugins. Understanding where collections are installed is essential for managing and customizing your Ansible automation workflows. This article explains the default installation paths for Ansible collections and how to customize them.
Where Are Ansible Collections Installed?
Default Installation Paths
By default, Ansible collections are installed in two primary locations depending on the type of user access:
Global Path: For system-wide installation, collections are stored under the Ansible system directory:
/usr/share/ansible/collections/
User Path: For user-specific installation, collections are stored in the user’s home directory:
~/.ansible/collections/
This location is typically used when running
ansible-galaxy collection install
without administrative privileges.
Verifying Installed Collections
To view all installed collections, use the following command:
ansible-galaxy collection list
This command outputs the collection name, version, and installation path.
How to Customize Collection Installation Paths
Ansible allows you to customize collection paths using the ANSIBLE_COLLECTIONS_PATHS
environment variable or by modifying the ansible.cfg
configuration file.
Using Environment Variables
Set a custom collection path using the ANSIBLE_COLLECTIONS_PATHS
environment variable:
export ANSIBLE_COLLECTIONS_PATHS=/custom/path/to/collections
This variable overrides the default paths during collection installation and execution.
Updating the Configuration File
Modify the ansible.cfg
file to define custom collection paths:
[defaults]
collections_paths = /custom/path/to/collections:/another/path
Multiple Paths
Ansible supports multiple collection paths. Specify them as a colon-separated list:
export ANSIBLE_COLLECTIONS_PATHS=/path1:/path2:/path3
The order of paths determines the priority when resolving collections.
Installing Collections in Custom Paths
To install collections in a specific directory, use the --collections-path
option:
ansible-galaxy collection install my_namespace.my_collection --collections-path /custom/path
This option installs the collection in the specified path instead of the default directories.
Why Customize Collection Paths?
Environment Isolation: Use custom paths to separate collections for different projects or environments.
Shared Resources: Centralize collections in a shared directory for collaborative teams.
Testing and Development: Use custom paths for developing and testing new collections.
Best Practices for Managing Collection Paths
Use Version Control: Store
ansible.cfg
or environment variables in version control to maintain consistency.Organize Paths: Separate production collections from test or development collections.
Leverage Defaults: Use default paths for simplicity unless customization is necessary.
Conclusion
Ansible collections are installed in user-specific or global directories by default, but you can customize their paths for better flexibility and organization. Whether you’re working in a shared environment or isolating collections for specific projects, understanding and managing collection paths ensures smooth automation workflows.
Learn More About Ansible Collections
Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.Academy
Explore more tips for managing Ansible collections in Ansible by Examples.
Donate
Support the project by contributing today.