//A Gitops Based Ansible QA Process in the Hybrid-Cloud

Platform Engineering

A Gitops Based Ansible QA Process in the Hybrid-Cloud

M Mentat CollectiveDec 15, 20226 min readShare

Introduction

Cloud illustration used as the GitOps Ansible QA hero image

At Mentat we like making things simple, secure, and scalable. So, we decided to create a fully automated Ansible QA process based on GitOps.

Quality and consistency of services delivered are arguably the largest differentiators between automation teams that succeed and automation teams that fail. Testing Ansible playbooks in feature branches can be difficult, unreliable, and daunting for teams adopting Ansible.

This is where a mature quality assurance testing harness becomes critical. There are no simple ways to truly test Ansible playbooks that modify operating systems and applications, and using a tool to validate itself is not much of a scientific test.

Based on growing client demand for consistent tests of Ansible playbooks within a complex hybrid-cloud environment, we created a GitOps-based approach that automatically deploys fresh virtual machines in major clouds, runs Ansible on all nodes, and reports the results back to a central pipeline platform.

Solution Tech Stack

Ansible — The Code.
Ansible Lint — The Code Defender.
Git — The Code Holder.
Azure DevOps — The Orchestration Engine.
Terraform — The Builder.
Azure Key Vault — The Secret Keeper.

Technical Summary

We started with Azure DevOps as the testing harness. Using git and Azure DevOps branch protection, we configured “don’t break the build” requirements so every pull or merge request from a feature branch to develop had to pass a successful pipeline run before it could be merged.

We attached three pipelines — one for each cloud — to the develop branch so they automatically execute whenever someone submits a PR or MR. That gives the team a repeatable, enforced gate for infrastructure and automation changes.

The pipeline itself is intentionally thin because most of the heavy lifting lives inside reusable templates. But the overall flow is straightforward:

Example DBTB pipeline
variables:
  - name: provider
    value: vmware
  - name: ansible_playbook
    value:vmware_base.yml
  - name: repo_branch
    ${{ if ne(parameters.repo_branch, '') }}:
      value: ${{ parameters.repo_branch }}

  - template: vars/vars-shared.yaml
  - template: vars/vars-linux.yaml
  - template: vars/vars-vmware.yaml

parameters:
  - name: repo_branch
    displayName: Ansible Repo Branch Name
    type: string
    default: ''

resources:
  repositories:
    - repository: templates
      type: git
      name: platform/pipeline-templates
      ref: develop

# CI Triggers
trigger:
  branches:
    exclude:
      - '*'

pool: $(pool)

# Release Stages
stages:
  - stage: Variables
    jobs:
      - job:
        steps:
          - template: steps/terragrunt-vmware.yaml@templates
          - template: ../common-pipeline-yamls/terraform-tfvars-${{ variables.provider }}.yaml
          - task: PublishPipelineArtifact@1
            inputs:
              targetPath: $(tf_directory)/terraform.tfvars
              artifactName: terraform_parameter_vars_$(tf_module)
  - template: terragrunt/terragrunt-apply.yaml@templates
    parameters:
      ado_environment: no_approval_required
      dont_break_the_build: true
  - template: ansible/ansible-lint.yaml@templates
    parameters:
      ado_environment: no_approval_required
      dont_break_the_build: true
  - template: ansible/ansible-apply.yaml@templates
    parameters:
      dont_break_the_build: true
  - template: terragrunt/terragrunt-destroy.yaml@templates
    parameters:
      ado_environment: no_approval_required
      dont_break_the_build: true

What Happens in the Pipeline

First, we execute a pipeline template that prepares the build agents to deploy a machine into VMware. That step securely retrieves the required authentication material from Azure Key Vault so the values never leak into pipeline output.

- template: steps/terragrunt-vmware.yaml@templates

Next, we generate a dynamic TFVars file from the Azure DevOps web-form submission and place it alongside the Terraform module being executed.

- template: ../common-pipeline-yamls/terraform-tfvars-${{ variables.provider }}.yaml

Then we run Terragrunt apply from a reusable pipeline template. Pipeline templates act like functions: they execute repeatable tasks in a known order so every Terraform build behaves the same way.

- template: terragrunt/terragrunt-apply.yaml@templates
  parameters:
    ado_environment: no_approval_required
    dont_break_the_build: true

After the infrastructure is ready, we run Ansible lint against the feature branch before allowing execution. Linting matters a lot at scale because it catches formatting, safety, and maintainability issues before they spread across a larger codebase.

- template: ansible/ansible-lint.yaml@templates
  parameters:
    ado_environment: no_approval_required
    dont_break_the_build: true
- template: ansible/ansible-apply.yaml@templates
  parameters:
    dont_break_the_build: true

If linting passes, the pipeline applies the Ansible playbook across VMs on all compute providers simultaneously. Once execution is complete, the final stage always destroys the temporary infrastructure so the test environment does not linger and burn money.

Outcomes

GitOps automated quality assurance testing harness.
Better quality code.
Near elimination of breaking code changes as issues are automatically caught.
Faster delivery of features.
More secure code because linting and related checks surface possible security gaps early.

P.S.

This one was intentionally short, but the pattern is powerful: branch protection, fresh test infrastructure, deterministic automation, and automatic teardown make Ansible QA much more trustworthy in hybrid-cloud environments.

A Gitops Based Ansible QA Process in the Hybrid-Cloud

Key takeaway

Ready to automate smarter?

Treat Ansible QA like infrastructure: create clean environments on demand, enforce branch protection, lint early, test across providers, and always clean up afterward.