.gitlab-ci.yml for “ansible-lint”

So I started working with GitLab (self-hosted and gitlab.com), which led me to the CI/CD features of GitLab. When using GitLab, one can define a custom CI pipeline just by placing a .gitlab-ci.yml file in your project (just like the .travis.yml for GitHub). After each commit to the defined git branch, the pipeline is then executed.

Since I also work with Ansible playbooks a lot, I wanted to use ansible-lint to check my playbooks after each commit. In addition to that, I also added a syntax check using ansible-playbook [..] --syntax-check, as ansible-lint will not pick up all syntax errors.

So here is my .gitlab-ci.yml:

---
# -*- coding: utf-8 -*-

before_script:
  - apt-get update -qy
  - apt-get install -y python-dev python-pip
  - git submodule update --init
  - pip install --upgrade ansible ansible-lint
  - ansible --version
  - ansible-lint --version

stages:
  - ansible-lint
  - ansible-syntax-check

ansible-lint:
  stage: ansible-lint
  script:
    - ansible-lint playbook.yml

ansible-syntax-check:
  stage: ansible-syntax-check
  script:
    - ansible-playbook --inventory inventory --syntax-check playbook.yml

Hello world

My name is Simon Krenger, I am a Technical Account Manager (TAM) at Red Hat. I advise our customers in using Kubernetes, Containers, Linux and Open Source.

Elsewhere

  1. GitHub
  2. LinkedIn
  3. GitLab