Ansible

2019, Jul 14    

I use ansible to provision servers, routers and other hardware and virtual machines.

Gitlab-CI snippet for syntax checking the ansible role

ansible_syntax_check:
  image: registry.gitlab.com/moozer/docker-deb-pip:latest
  before_script:
   - git submodule sync --recursive
   - git submodule update --init --recursive
   - pip3 install ansible ansible-lint

  script:
  - echo localhost > ci-inventory
  - ansible-playbook --syntax-check site.yml -i ci-inventory
  - ansible-lint site.yml
  - ansible-playbook site.yml --connection=local -l localhost -i ci-inventory
  - ansible-playbook site.yml --connection=local -l localhost -i ci-inventory | grep -q 'changed=0.*failed=0'

This works is the inventory is part of the repo or if it is a submodule. I already use a submodule for each role, so I need the submodule retrieval part.

ansible-galaxy didn’t work for me. Feel free to send me some descriptions/guides to convince me that it is better than submodules.

We should also start to look at molecule

Read this about testing on page 15 of this presentation by Magnus Glantz Some hints used from geerlinguy