Introduction
Ansible is a powerful automation and configuration management tool that allows you to streamline and simplify complex IT tasks. One of Ansible's key features is the use of collections, which are shareable units of automation, and can be hosted on Ansible Galaxy. Collections help automate various tasks efficiently. However, ensuring that your Ansible collections are well-maintained and follow best practices is crucial for seamless automation.
In this article, we'll discuss the Ansible "galaxy" rule, which is designed to identify and address issues related to the quality and completeness of your Ansible collections. This rule serves as a helpful guide to maintaining and certifying your collections on Automation Hub or Galaxy NG.
Collection Version
One of the first aspects the "galaxy" rule checks is the collection version specified in your galaxy.yml file. It ensures that the collection's version is greater than or equal to 1.0.0. This requirement ensures that your collection follows a standard versioning convention, with the goal of indicating that it's a production-ready release. For example:
Problematic Code
``yaml
galaxy.yml
---
name: my_collection
namespace: my_namespace
version: 0.2.3 # Collection version should be >= 1.0.0
`
Output
`bash
WARNING Listing 5 violation(s) that are fatal
galaxy[no-changelog]: No changelog found. Please add a changelog file. Refer to the galaxy.md file for more info.
test/galaxy/galaxy.yml:1
galaxy[tags]: galaxy.yaml must have one of the required tags: ['application', 'cloud', 'database', 'infrastructure', 'linux', 'monitoring', 'networking', 'security', 'storage', 'tools', 'windows']
test/galaxy/galaxy.yml:1
schema[galaxy]: $ 'readme' is a required property. See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html
test/galaxy/galaxy.yml:1 Returned errors will not include exact line numbers, but they will mention
the schema name being used as a tag, like schema[playbook],
schema[tasks].
This rule is not skippable and stops further processing of the file.
If incorrect schema was picked, you might want to either:
* move the file to standard location, so its file is detected correctly.
* use kinds:` option in linter config to help it pick correct file type.
galaxy[version-incorrect]: collection version should be greater than or equal to 1.0.0
test/galaxy/galaxy.yml:5
yaml[empty-lines]: Too many blank lines (1 > 0)
test/galaxy/galaxy.yml:6
Read documentation for instructions on how to ignore specific rule violations.
Rule Violation Summary
count tag profile rule associated tags
1 schema[galaxy] basic core
1 yaml[empty-lines] basic formatting, yaml
1 galaxy[no-changelog] shared metadata
1 galaxy[tags] shared metadata
1 galaxy[version-incorrect] sh