diff --git a/.gitignore b/.gitignore index a058c8c..22ee3cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vagrant *.retry +.molecule +**__pycache__** diff --git a/.travis.yml b/.travis.yml index f2ff2cf..badbc0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,20 @@ ---- +sudo: required language: python -python: "2.7" - -sudo: true - -# Install ansible -addons: - apt: - packages: - - python-pip - +cache: pip +services: + - docker +env: + - ANSIBLE=2.2.3 + - ANSIBLE=2.3.2 + - ANSIBLE=2.4.2 install: - # Install ansible - - pip install ansible - - # Check ansible version - - ansible --version - - # Create ansible.cfg with correct roles_path - - printf '[defaults]\nroles_path=../' >ansible.cfg - + - pip install ansible==${ANSIBLE} ansible-lint>=3.4.15 molecule==1.25.0 docker git-semver testinfra>=1.7.0 +before_script: + - ansible-lint tests/playbook.yml script: - # Basic role syntax check - - ansible-playbook tests/test.yml -i tests/inventory --syntax-check - - ansible-playbook tests/test.yml -i tests/inventory --connection=local - - ansible-playbook tests/test.yml -i tests/inventory --connection=local - - > - ansible-playbook tests/test.yml -i tests/inventory --connection=local - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) - + - molecule test +branches: + only: + - master notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.travis/images.sh b/.travis/images.sh new file mode 100755 index 0000000..20395a7 --- /dev/null +++ b/.travis/images.sh @@ -0,0 +1,7 @@ +#!/bin/bash +for i in ubuntu-molecule:16.04 debian-molecule:9 debian-molecule:8 centos-molecule:7 fedora-molecule:27 +do + docker pull paulfantom/$i & +done + +wait diff --git a/molecule.yml b/molecule.yml new file mode 100644 index 0000000..55d5d8b --- /dev/null +++ b/molecule.yml @@ -0,0 +1,43 @@ +--- +ansible: + playbook: tests/playbook.yml +driver: + name: docker +verifier: + name: testinfra +dependency: + name: shell + command: ./.travis/images.sh +docker: + build_image: False + containers: + - name: xenial + image: paulfantom/ubuntu-molecule + image_version: 16.04 + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: stretch + image: paulfantom/debian-molecule + image_version: 9 + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: jessie + image: paulfantom/debian-molecule + image_version: 8 + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: centos7 + image: paulfantom/centos-molecule + image_version: 7 + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: fedora + image: paulfantom/fedora-molecule + image_version: 27 + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro diff --git a/tests/test.yml b/tests/playbook.yml similarity index 100% rename from tests/test.yml rename to tests/playbook.yml diff --git a/tests/test_default.py b/tests/test_default.py new file mode 100644 index 0000000..bca1dbe --- /dev/null +++ b/tests/test_default.py @@ -0,0 +1,37 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + +def test_files(host): + dirs = [ + "/etc/caddy", + "/opt/node_exporter" + ] + for dir in dirs: + d = host.file(dir) + assert d.exists + assert d.is_directory + + +def test_packages(host) + pkgs = [ + "git" + ] + for p in pkgs: + assert host.package(p).is_installed + + +def test_service(host): + s = host.service("caddy") + assert s.is_enabled + assert s.is_running + + +def test_socket(host): + sockets = [ + "tcp://localhost:2020" + ] + for socket in sockets: + s = host.socket(socket) + assert s.is_listening