Molecule using Docker
Closed this issue · 0 comments
In order to use Travis and Molecule, it is mandatory to use Docker: Travis doesn't support Vagrant. The problem was that the tests use Ansible module and it needs an Ansible backend connection and, when Docker driver is specified, Molecule uses Testinfra with the argument --connection=docker
, making the tests fail, as they don't find any host.
To make it work, we just have to force Testinfra to use the same arguments as the Vagrant driver. These arguments are: --connection=ansible --ansible-inventory=.molecule/ansible_inventory
, so in molecule.yml
, we specify these arguments in verifier
section:
verifier:
name: testinfra
options:
connection: ansible
ansible-inventory: .molecule/ansible_inventory
Docker driver configuration is a bit tricky itself: as our role is using systemd
, default image configuration won't work. To make Docker container use systemd
, we have to add this in the container configuration in molecule.yml
:
privileged: True
cap_add:
- SYS_ADMIN
volume_mounts:
- '/sys/fs/cgroup:/sys/fs/cgroup:ro'
command: '/lib/systemd/systemd'
Finally, looks like default Debian images come with Python 2.7.9 and it makes pip crack somehow after Airflow installation, so we have to use Python images. Knowing all of this, the Docker section in molecule.yml
states like this:
docker:
containers:
- name: airflow.vm
ansible_groups:
- airflow
image: python
image_version: 2.7.13-jessie
port_bindings:
80: 80
8080: 8080
5555: 5555
privileged: True
cap_add:
- SYS_ADMIN
volume_mounts:
- '/sys/fs/cgroup:/sys/fs/cgroup:ro'
command: '/lib/systemd/systemd'