I suggest you should read the whole series or at least start with the previous one to get the full context. Below is the link for the previous article.
What is Ansible Collection?
It is a set of similar modules which can do a couple of tasks for the given environment/region/cloud-provider/software/etc.
Why we need Ansible Collection?
Before Ansible 2.9.10 version, Ansible Modules were packed into Ansible Packages and All the modules have to meet a certain level of standard as they will be shipped with the official product and that lead serious issue which is the delay in the new modules.
After Ansible 2.9.10 version, Ansible Team decided to split modules into a separate set of collections which will do be very specific jobs for a given use case and increase the speed of the new module rollout as well.
A new pattern was created to package these modules so they can be easily plugged into Ansible and that is called Collection/Ansible Collection.
- so on
Ansible Core Team composed a document to layout basic details of the Collection and its ingredients.
Let’s talk about the structure of the Ansible Collection.
$ tree -L 3
│ ├── community.missing_collection.aws_amp_info_module.rst
│ ├── community.missing_collection.aws_amp_module.rst
│ ├── community.missing_collection.mapr_service_module.rst
│ └── community.missing_collection.newrelic_deployment_module.rst
│ └── runtime.yml
│ ├── modules
│ │ ├── aws_amp_info.py
│ │ ├── aws_amp.py
│ │ ├── __init__.py
│ │ ├── mapr_service.py
│ │ └── newrelic_deployment.py
│ └── module_utils
│ ├── aws_response_parser.py
│ ├── __init__.py
│ └── utils.py
│ └── aws
└── readme.md8 directories, 387 files
galaxy.yml: It includes things like “namespace”, “name”, “version”, and so on which you should set, some of them are optional but it’s much better to just set them once and forget about it.
Notes: “community”, “ansible” and a couple of namespaces are reserved for Ansible and you can’t publish a collection with these names to Ansible Collection Website: https://galaxy.ansible.com which is similar to Docker Hub for Docker Images at http://store.docker.com.
$ cat galaxy.yml
- Davinder Pal (@116davinder) <firstname.lastname@example.org>
description: It will contains all the modules which are missing in official ansible collections.
tags: [community, aws, cloud, amazon]
meta/runtime.yml: It only stores the ansible required version for now.
$ cat meta/runtime.yml
LICENSE is optional things but I highly recommend you to use these one’s because someone might sell your content to others which is freely available to everyone.
README is semi-optional because later it will be used in automated doc creation and it store other important notes/links for the repository which will be used by the general user to understand your collection better.
docs is a common folder name to store auto-generated documentation for collection modules.
tests is a common folder name where you can store example/test codebase for your collection modules.
plugins/modules is where you will put your ansible modules.
plugins/module_utils is where you will put any shared code which can be used across multiple modules within the collection.
Once you are used to this structure then it becomes super easy to understand other collections and how they operate.
Please take a break and review the collections mentioned in the below link.
Have Fun!, I will be back soon with the next part of the series.