Download and Use Ansible Galaxy Collection - ansible-galaxy and requirements.yml
How to Download and use the Ansible Collection community.general re-using Ansible artifacts (tasks, variables, defaults, handlers, modules, and plugins) published in Ansible Galaxy directory.


How to Download and Use Ansible Galaxy Role with ansible-galaxy and requirements.yml? I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
What is an Ansible Collection?
- distribution format for Ansible content
- it contains the package and distributes playbooks, roles, modules, and plugins using collections
- easy to download and share via Ansible Galaxy
An Ansible Collection is a distribution format for Ansible content. It solves one problem and contains all the relevant contains the package and distributes playbooks, roles, modules, and plugins. For Users, the Ansible Collection is easy to download and share via Ansible Galaxy. For Developers the Ansible Collection is easy to upload and share via Ansible Galaxy. Plus an Ansible Collection has a defined standard directory structure and format.
What is Ansible Galaxy?
The website is available at the URL https://galaxy.ansible.com/. The search engine, Tags, and Platform make it easy to find any content inside. I recommend you carefully evaluate the quality of content before using it in your system. Quality indicators are usually the quality assurance of code, the supported operating systems and platforms, the documentation, the release numbers, the presence of Changelog, the number of downloads, and the author or creator. Please notice that the website contains Ansible Roles and Ansible Collections. Today we’re focusing on Ansible Role content.
Links
- Ansible Collections list
- Ansible Collections Developer Guide
- Ansible Collections migrating roles
- community.general collection
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
Let’s jump into a real-life How to Download and Use the Ansible Galaxy Collection community.general
in a system with ansible-core
installed.
code
- collection.yml
---
- name: modprobe module demo
hosts: localhost
become: true
vars:
module_name: "dummy"
ansible_connection: local
tasks:
- name: load the module
community.general.modprobe:
name: "{{ module_name }}"
state: present
- requirements.yml
---
collections:
- name: community.general
source: https://galaxy.ansible.com
execution without collection installed
$ ansible-playbook collection/collection.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'
ERROR! couldn't resolve module/action 'community.general.modprobe'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/devops/collection/collection.yml': line 10, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: load the module
^ here
$
download execution
$ ansible-galaxy install -r collection/requirements.yml
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/community-general-4.5.0.tar.gz to /home/devops/.ansible/tmp/ansible-local-24543cs6dck7/tmpaccd0umv/community-general-4.5.0-5msjuuoa
Installing 'community.general:4.5.0' to '/home/devops/.ansible/collections/ansible_collections/community/general'
community.general:4.5.0 was installed successfully
list installed collection
$ ansible-galaxy collection list
# /home/devops/.ansible/collections/ansible_collections
Collection Version
----------------- -------
community.general 4.5.0
$
execution with collection installed
$ ansible-playbook collection/collection.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'
PLAY [modprobe module demo] ***********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [localhost]
TASK [load the module] ****************************************************************************
changed: [localhost]
PLAY RECAP ****************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$
Recap
Now you know how to Download and Use Ansible Galaxy Collection community.general
with Ansible.
Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate