Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 2.14 KB

README.md

File metadata and controls

85 lines (61 loc) · 2.14 KB

Automated tests for Ansible playbooks

Most playbooks in this repo contain automated tests implemented using Molecule.

Use Makefile provided in this directory to launch tests.

For example:

$ make
..Execute automated tests for all roles..

$ make test ANSIBLE_ROLE=../roles/motd
..Execute tests for a single role at provided path..

$ make login ANSIBLE_ROLE=../roles/motd
..Provision Docker container, apply the role and start interactive shell..

Refer to make help and read the Makefile for more information.




Some notes on tests implementation

Timeout for command/shell modules

Timeout is not implemented in Ansible, but we can use GNU Timeout, e.g.

$ timeout 5m sleep 10m
Exit code: 124 (after 5 minutes)

$ timeout 10m sleep 5m
Exit code: 0 (after /bin/sleep terminates)

Systemd in Docker

platforms:
  - name: debian10-docker
    image: potyarkin/molecule:debian-10-systemd
    pre_build_image: true
    command: /sbin/init
    capabilities:
      - SYS_ADMIN
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
      - /lib/modules:/lib/modules:ro
    tmpfs:
      - /run
      - /tmp

Ansible verifier for Molecule

See roles/transmission for example.

Useful modules:

  • assert
  • command
  • fail
  • package_facts
  • ping
  • service_facts
  • wait_for

Useful techniques:

  • Early exit: failed_when

Links: