Skip to content

Commit

Permalink
Switch tests to use Molecule.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Sep 29, 2018
1 parent af1ec62 commit eba1a00
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
*.retry
tests/test.sh
*/__pycache__
*.pyc
36 changes: 24 additions & 12 deletions .travis.yml
@@ -1,22 +1,34 @@
---
language: python
services: docker

env:
- distro: centos7
- distro: centos6
- distro: ubuntu1604
- distro: ubuntu1404
- distro: fedora27
- distro: debian9
- distro: debian8
global:
- ROLE_NAME: ntp
matrix:
- MOLECULE_DISTRO: centos7
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
- MOLECULE_DISTRO: centos6
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: ubuntu1404
- MOLECULE_DISTRO: fedora27
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
- MOLECULE_DISTRO: debian9
- MOLECULE_DISTRO: debian8

script:
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
install:
# Install test dependencies.
- pip install molecule docker

before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
- cd geerlingguy.$ROLE_NAME

script:
# Run tests.
- ${PWD}/tests/test.sh ${distro}
- molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -12,15 +12,15 @@ None.

Available variables are listed below, along with default values (see `defaults/main.yml`):

ntp_enabled: True
ntp_enabled: true

Whether to start the ntpd service and enable it at system boot. On many virtual machines that run inside a container (like OpenVZ or VirtualBox), it's recommended you don't run the NTP daemon, since the host itself should be set to synchronize time for all it's child VMs.

ntp_timezone: Etc/UTC

Set the timezone for your server.

ntp_manage_config: False
ntp_manage_config: false

Set to true to allow this role to manage the NTP configuration file (`/etc/ntp.conf`).

Expand Down
4 changes: 2 additions & 2 deletions defaults/main.yml
@@ -1,8 +1,8 @@
---
ntp_enabled: True
ntp_enabled: true
ntp_timezone: Etc/UTC

ntp_manage_config: False
ntp_manage_config: false

# NTP server area configuration (leave empty for 'Worldwide').
# See: http://support.ntp.org/bin/view/Servers/NTPPoolServers
Expand Down
10 changes: 5 additions & 5 deletions handlers/main.yml
@@ -1,6 +1,6 @@
---
- name: restart ntp
service:
name: "{{ ntp_daemon }}"
state: restarted
when: ntp_enabled
- name: restart ntp
service:
name: "{{ ntp_daemon }}"
state: restarted
when: ntp_enabled
14 changes: 7 additions & 7 deletions meta/main.yml
Expand Up @@ -10,25 +10,25 @@ galaxy_info:
platforms:
- name: EL
versions:
- all
- all
- name: Fedora
versions:
- all
- all
- name: Debian
versions:
- all
- all
- name: Ubuntu
versions:
- all
- all
- name: FreeBSD
versions:
- all
- all
- name: Suse
versions:
- all
- all
- name: Archlinux
versions:
- all
- all
galaxy_tags:
- system
- ntp
Expand Down
27 changes: 27 additions & 0 deletions molecule/default/molecule.yml
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
platforms:
- name: instance
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
9 changes: 6 additions & 3 deletions tests/test.yml → molecule/default/playbook.yml
@@ -1,4 +1,7 @@
- hosts: all
---
- name: Converge
hosts: all
become: true

vars:
ntp_enabled: false
Expand All @@ -7,9 +10,9 @@
pre_tasks:
- name: Update apt cache.
apt:
update_cache: yes
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'

roles:
- role_under_test
- role: geerlingguy.ntp
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
@@ -0,0 +1,14 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
6 changes: 6 additions & 0 deletions molecule/default/yaml-lint.yml
@@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
4 changes: 2 additions & 2 deletions tasks/main.yml
Expand Up @@ -24,14 +24,14 @@
service:
name: "{{ ntp_daemon }}"
state: started
enabled: yes
enabled: true
when: ntp_enabled

- name: Ensure NTP is stopped and disabled as configured.
service:
name: "{{ ntp_daemon }}"
state: stopped
enabled: no
enabled: false
when: not ntp_enabled

- name: Generate ntp.conf file
Expand Down
11 changes: 0 additions & 11 deletions tests/README.md

This file was deleted.

0 comments on commit eba1a00

Please sign in to comment.