Example CI/CD Pipeline for an Ansible Collection
CI/CD Pipelines for Ansible Collections
To streamline the development and release process of Ansible collections, you can create a CI/CD pipeline that includes code validation and manual steps for releasing a new version of an Ansible collection to Ansible Galaxy.
To streamline the development and release process of Ansible collections, you can integrate Git with CI/CD pipelines. The example
.gitlab-ci.yml file attached to this page provides a template pipeline that includes code validation and manual steps for releasing a new version of an Ansible collection to Ansible Galaxy.
The file contains the configuration for the pipeline stages and jobs:
prepare job in the build stage extracts the collection version, name, and namespace from the
galaxy.yml file and saves them as environment variables for later use. It creates a
variables.env file to store these variables as artifacts.
build job packages the Ansible collection and generates the
README.md file from
README-GALAXY.md. The resulting collection is stored as an artifact.
yamllint job runs the
yamllint tool to validate the YAML code.
ansible-lint job installs the collection built in the previous stage and runs the
ansible-lint tool to validate the Ansible code.
publish job publishes the Ansible collection to Ansible Galaxy. It packages the collection, generates the
README.md file from
README-GALAXY.md, and publishes it to Ansible Galaxy using the provided API key.
gitlab-release job creates a release in GitLab for the Ansible collection. It uses the information from
galaxy.yml, including the version and changelog, to create the release. The release is associated with the commit and can be accessed through the provided release name.
To use this pipeline as a template for your Ansible collections, follow these steps:
- Set up your GitLab repository with the necessary configuration files:
- Configure the stages and jobs in the
.gitlab-ci.ymlfile based on your specific requirements. Copy the updated pipeline configuration provided below.
- Update the
galaxy.ymlfile with the relevant information for your Ansible collection, such as the namespace, name, version, description, and links to documentation and issues.
- Ensure you have the required dependencies installed, including Python, Pip, Ansible, yq, yamllint, and ansible-lint. Adjust the package installation commands in the
before_scriptsection of the
.gitlab-ci.ymlfile if needed.
- Set up the necessary environment variables and secrets in your GitLab CI/CD settings, including the
GALAXY_API_KEYfor publishing to Ansible Galaxy.
- Commit and push your changes to trigger the pipeline. The pipeline will run on merge requests and the default branch.
By integrating Git with CI/CD pipelines for Ansible collections, you can achieve the following benefits:
- Ensure code quality by validating the YAML and Ansible code.
- Automate the process of building and publishing collections to Ansible Galaxy.
- Track and create releases in GitLab, associating them with specific commits and providing changelog information.
- example attached to attached to this page.
- See the
.gitlab-ci.ymlof the Ansible collection
c2platform.gis. This project also includes an Azure CI/CD pipeline see
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.