Recently, I have been publishing some Ansible roles on GitHub, so I have been thinking about what kind 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.
image: python:3-slim before_script: - pip install ansible ansible-lint - ansible-lint --version stages: - ansible-lint ansible-lint: stage: ansible-lint script: - ansible-lint .
version: 2 jobs: build: docker: - image: python:3-slim steps: - checkout - run: pip install ansible ansible-lint - run: ansible-lint --version - run: ansible-lint .
language: python install: - pip install ansible ansible-lint - ansible-lint --version script: - ansible-lint .
name: ansible-lint on: [push] jobs: build: runs-on: ubuntu-latest name: ansible-lint steps: - uses: actions/[email protected] - uses: actions/[email protected] - run: pip install ansible ansible-lint - run: ansible-lint --version - run: ansible-lint .
Edit: I switched to GitHub actions now because it's easier to not rely on a third party service. Also all my Circle builds started to fail mysteriously...