Skip to content

Instantly share code, notes, and snippets.

@resmo
Created April 25, 2022 13:22
Show Gist options
  • Save resmo/40c973585a86996a515dce3be6c54d60 to your computer and use it in GitHub Desktop.
Save resmo/40c973585a86996a515dce3be6c54d60 to your computer and use it in GitHub Desktop.
ansible gitlab ci
---
image: python:3.8-slim-bullseye
variables:
ANSIBLE_FORCE_COLOR: "true"
VIRTUAL_ENV: .venv
PIP_REQUIRE_VIRTUALENV: "true"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache: &global_cache
key:
files:
- requirements.lock.txt
- requirements.yml
paths:
- .venv/
- collections/
- roles_galaxy/
- .cache/
policy: pull-push
stages:
- install
- check
.common:
cache:
<<: *global_cache
policy: pull
before_script:
- echo $ANSIBLE_VAULT_PASSWORD > .vault
# https://docs.ansible.com/ansible/devel/reference_appendices/config.html#avoiding-security-risks-with-ansible-cfg-in-the-current-directory
- chmod 0750 .
- python -m venv .venv
- source .venv/bin/activate
- apt-get update && apt-get install -y git
- pip install --upgrade pip wheel
- pip install -r requirements.lock.txt
- chmod 0644 ansible.cfg
- ansible-galaxy collection install -r requirements.yml
- ansible-galaxy role install -r requirements.yml
install:
extends: .common
cache:
<<: *global_cache
policy: pull-push
stage: install
script: ansible --version
ansible_lint:
extends: .common
stage: check
script:
- pip install -U ansible-lint
- ansible-lint playbooks/*.yml
allow_failure: true
yaml_lint:
extends: .common
stage: check
script:
- pip install -U yamllint
- yamllint --strict --format colored .
allow_failure: true
safety:
extends: .common
stage: check
script:
- pip install -U safety
- safety check -r requirements.lock.txt
allow_failure: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment