Recently, I have been publishing some Ansible roles on GitHub, so I have been thinking about what king of CI to set up.

The most famous tool for this task is Molecule (that's what we use at work). It can run entire test playbooks to make sure they work exactly as expected.

I really don't have the time to do that, and my roles are not critical for production, so I settled for a simple linting pipeline. I am using the also well-know ansible-lint which will validate the YAML files and enforce Ansible best practices.

Since it's as simple as running ansible-lint . in your Ansible role directory, I will share below some simple pipeline configurations for the most famous CI/CD tools.

It requires not configuration, you'll just need to add the repository to the CI service as usual, and then commit the correct configuration file!

I am currently using CircleCI for this specific pipeline. The tree services work identically, but CircleCI is the fastest to trigger and run the pipeline.

GitLab CI

.gitlab-ci.yml:

image: python:3-slim

before_script:
  - pip install ansible-lint
  - ansible-lint --version

stages:
  - ansible-lint

ansible-lint:
  stage: ansible-lint
  script:
    - ansible-lint .

Travis CI:

.circle-ci/config.yml:

version: 2
jobs:
  build:
    docker:
      - image: python:3-slim
    steps:
      - checkout
      - run: pip install ansible-lint
      - run: ansible-lint --version
      - run: ansible-lint .

CircleCI

.travis.yml:

language: python
install:
  - pip install ansible-lint
  - ansible-lint --version
script:
  - ansible-lint .