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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Best Tools for Software Composition Analysis (SCA)

Here’s a clear and professional explanation of the three related concepts you asked about — all of which are critical parts of secure software development, especially in…

Read More

Top 10 AI Code Review Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI code review tools have become essential for developers aiming to enhance code quality, streamline workflows, and accelerate software delivery. These tools leverage advanced…

Read More

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

Introduction Expense management tools are critical for businesses of all sizes in 2026 as they help streamline financial processes, improve budgeting, ensure compliance, and enhance financial visibility….

Read More

Top 10 Web Application Firewall (WAF) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In the rapidly evolving landscape of cybersecurity, Web Application Firewalls (WAFs) have become a critical component in defending web applications from malicious attacks such as SQL…

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

Top 11 Best Apps for Education

Are you tired of traditional learning methods? Do you want to explore new ways of learning? Then you have come to the right place! In this article,…

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