AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Automate Ansible Collection Testing with GitHub Actions — Video Tutorial

Learn how to automate testing for Ansible collections using GitHub Actions. This guide covers setting up .github/test.yml for reliable CI/CD and validation.

Watch Video

Watch "Automate Ansible Collection Testing with GitHub Actions" on YouTube

What You'll Learn

Full Tutorial Content

Introduction GitHub Actions provides a powerful and flexible platform for automating workflows directly within your GitHub repository. One common use case is automating the testing of collections in Ansible, ensuring that each component functions as expected. This article will guide you through the setup of a GitHub Actions workflow for testing Ansible collections using the `.github/test.yml` configuration. Understanding the Configuration Let's break down the structure of the `.github/test.yml` file: ```yaml name: GHA for foo.bar concurrency: group: ${{ github.head_ref || github.run_id }} cancel-in-progress: true on: pull_request: branches: [main] workflow_dispatch: schedule: - cron: '0 0 * * *' ``` - **name**: Describes the name of the GitHub Actions workflow. - **concurrency**: Specifies concurrency settings, ensuring that workflows do not interfere with each other. The `group` attribute combines workflows under the same conditions, and `cancel-in-progress` cancels any currently running workflow if a new one is triggered. - **on**: Defines the events that trigger the workflow. In this case, the workflow is triggered on pull requests targeting the `main` branch, manually using workflow_dispatch, and on a daily schedule. Now, let's look at the job definitions: ```yaml jobs: ansible-lint: uses: ansible-network/github_actions/.github/workflows/ansible-lint.yml@main changelog: uses: ansible-network/github_actions/.github/workflows/changelog.yml@main integration: uses: ansible-network/github_actions/.github/workflows/integration_simple.yml@main sanity: uses: ansible-network/github_actions/.github/workflows/sanity.yml@main unit-galaxy: uses: ansible-network/github_actions/.github/workflows/unit_galaxy.yml@main ``` - **jobs**: Lists the individual jobs that will be executed. Each job is defined separately and utilizes existing workflows from the `ansible-network/github_actions` repository. - `ansible-lint`, `changelog`, `integration`, `sanity`, and `unit-galaxy` are examples of jobs that can be run independently. Next is the `all_green` job: ```yaml all_green: if: ${{ always() && (github.event_name != 'schedule') }} needs: - changelog - integration - sanity - unit-galaxy runs-on: ubuntu-latest steps: - run: >- python -c "assert set([ '${{ needs.changelog.result }}', '${{ needs.integration.result }}', '${{ needs.sanity.result }}', '${{ needs.unit-galaxy.result }}' ]) == {'success'}" ``` - **all_green**: This job runs only if certain conditions are met. It runs on the latest version of Ubuntu and depends on the successful completion of the `changelog`, `integration`, `sanity`, and `unit-galaxy` jobs. - **steps**: Specifies the steps to be executed within the job. In this case, it runs a Python script to assert that the results of the dependent jobs are all 'success'. If any job f

About This Tutorial

Read the full written article: Automate Ansible Collection Testing with GitHub Actions

Topics Covered

Related Video Tutorials