Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

What is Ansible Collection?

What is Ansible Collection?

Ansible Collections are a standardized packaging format for distributing Ansible content (roles, modules, plugins, playbooks, and documentation). Introduced in Ansible 2.9+, collections allow you to easily share, install, and manage sets of automation assets together.

  • A collection organizes content under a common namespace and name (e.g., community.mysql).
  • It may include:
    • Roles
    • Playbooks
    • Modules
    • Plugins (lookup, filter, callback, etc.)
    • Documentation and tests

Before Collections

Earlier, most content was shipped with Ansible or required to be managed separately as roles (via Ansible Galaxy). There was no simple, standard bundle for sharing custom modules, plugins, and roles together. Collections solve these challenges by grouping and versioning all content for modular use and distribution.

Why Do We Need Ansible Collections?

  • Modularity: Package all automation content (plugins, modules, roles, playbooks, docs) together, decoupled from Ansible core.
  • Versioning: Install and use specific versions, enabling more reliable dependency management for automations.
  • Distribution: Distribute content via platforms like Ansible Galaxy, Automation Hub, or private repositories.
  • Community & Vendor Content: Use well-defined namespaces (e.g., community.general, cisco.ios) for community- or vendor-created collections.
  • Upgrades and Maintenance: Update collections independently of Ansible engine, making it easier to keep automation content up to date.

How to Use Ansible Collections

1. Installing a Collection

Install a collection from Galaxy or Automation Hub:

bashansible-galaxy collection install community.mysql
  • By default, collections are installed to ~/.ansible/collections or globally if run as root.

Install a specific version:

bashansible-galaxy collection install community.mysql:==3.8.0

2. Listing Installed Collections

bashansible-galaxy collection list

3. Using Collection Content in Playbooks

  • Modules/Plugins: Use the Fully-Qualified Collection Name (FQCN), e.g., community.mysql.mysql_db.
text- name: Create a MySQL database
  hosts: dbservers
  tasks:
    - name: Create database
      community.mysql.mysql_db:
        name: example
        state: present
        login_user: root
        login_password: s3cret
  • Roles: Reference within roles section:
textroles:
  - role: community.mysql.mysql_role
  • Plugins: Loaded automatically when present in installed collections.

4. Using Collections in the collections: Block

You can reduce boilerplate by declaring required collections at the playbook level:

text---
- hosts: all
  collections:
    - community.mysql
  tasks:
    - mysql_db:
        name: test
        state: present
  • The task will now use community.mysql.mysql_db as just mysql_db.

5. Using Collections in Requirements

Declare project dependencies in a requirements.yml:

textcollections:
  - name: community.mysql
    version: ">=3.8.0,<4.0.0"
  - name: amazon.aws

Install all requirements:

bashansible-galaxy collection install -r requirements.yml

How to Create an Ansible Collection

1. Initialize a Collection Skeleton

bashansible-galaxy collection init my_namespace.my_collection
  • Produces my_namespace/my_collection/ with directories for plugins, roles, docs, tests, etc.

2. Add Content

  • Place modules in plugins/modules/
  • Put roles in roles/
  • Add filter plugins, lookup plugins, etc., in corresponding plugin directories.
  • Add documentation in docs/
  • Write tests in tests/

3. Edit galaxy.yml

Defines collection metadata, dependencies, authors, etc.

  • Namespace and name
  • Description
  • License, etc.

4. Build the Collection Package

From the root collection directory:

bashansible-galaxy collection build
  • Creates a .tar.gz distributable artifact.

5. Publish or Share

  • Publish to Ansible Galaxy (requires account): bashansible-galaxy collection publish ./my_namespace-my_collection-*.tar.gz
  • Or upload to Automation Hub/private repo.

Advanced: Developing & Testing a Collection

  • Use ansible-test for unit and integration tests (tests/ directory).
  • Use molecule for role/playbook scenario testing (see [previous suggestions]).

Other Important Details/Missing Info

  • Namespace Conventions: Namespace must be unique (vendor, project, or username; lowercase, no spaces).
  • Dependencies: List other collections as dependencies in galaxy.yml (dependencies: key).
  • Documentation: Each module, role, or plugin should have YAML/Markdown docs for Galaxy rendering.
  • Collection Path Precedence: Ansible resolves content in this order: playbook/project collections/ → user’s default location → system path.
  • Backward Compatibility: Older content (roles, modules) should be refactored into collections for modern workflows.
  • Private Collections: You can run your own Galaxy/Automation Hub server for internal sharing.

Summary Table

ActionCommand/Step
Install a collectionansible-galaxy collection install <namespace>.<name>
Use a module from a collectionnamespace.collection.module or via collections: block
List installed collectionsansible-galaxy collection list
Initialize a collection skeletonansible-galaxy collection init ns.coll
Build collection for distributionansible-galaxy collection build
Publish to Galaxyansible-galaxy collection publish <tarball>
Add dependencies in collectionEdit galaxy.yml (dependencies section)
Use dependencies in projectAdd to requirements.yml, then install

References

  • [Official Ansible Collections Documentation]
  • [Ansible Galaxy Collections Guide]
  • [Red Hat Automation Hub Collection Info]

: https://docs.ansible.com/ansible/latest/dev_guide/collections_tech.html
: https://galaxy.ansible.com/docs/collections.html
: https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/2.5/html-single/getting_started_with_automation_hub/index

In summary:
Ansible Collections are a modern, standardized mechanism to organize, share, and version all types of Ansible content. You use them to install and consume content (modules, roles, plugins) with clear namespaces and manageable dependencies. You create them with ansible-galaxy collection init, add content, build, and (optionally) publish. They are essential for scale, modularity, and modern Ansible workflows.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 AI Pricing Optimization Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI pricing optimization tools have become indispensable for businesses navigating the complexities of dynamic markets. These tools leverage artificial intelligence, machine learning, and real-time…

Read More

Top 10 On-premise Backup Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, on-premise backup tools are still essential for businesses that need complete control over their data security and disaster recovery plans. Unlike cloud-based solutions, on-premise…

Read More

Top 10 Server Backup Tools in 2026: Features, Pros, Cons & Comparison

Introduction Server backup tools are essential for businesses in 2026 to ensure the safety, security, and reliability of their data. With the growing threats of cyberattacks, hardware…

Read More

Top 10 Backup & Recovery Tools in 2026: Features, Pros, Cons & Comparison

Introduction In today’s digital world, data is the backbone of virtually every business operation. As the amount of critical data grows, so does the need for robust…

Read More

Top 10 Disaster Recovery Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, disaster recovery (DR) is more crucial than ever. Businesses rely heavily on digital infrastructure, and even brief disruptions can lead to significant financial losses,…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devices—laptops, desktops, mobile devices, and other endpoints—that connect to their networks. With the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x