summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml37
-rw-r--r--tasks/main.yml13
-rw-r--r--tests/README.md9
4 files changed, 19 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c9b2377
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.retry
+tests/test.sh
diff --git a/.travis.yml b/.travis.yml
index 494f809..5e152aa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,44 +3,19 @@ services: docker
env:
- distro: centos7
- init: /usr/lib/systemd/systemd
- run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: centos6
- init: /sbin/init
- run_opts: ""
- distro: ubuntu1604
- init: /lib/systemd/systemd
- run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1404
- init: /sbin/init
- run_opts: ""
- distro: ubuntu1204
- init: /sbin/init
- run_opts: ""
-
-before_install:
- # Pull container.
- - 'docker pull geerlingguy/docker-${distro}-ansible:latest'
+ # - distro: debian8
script:
- - container_id=$(mktemp)
- # Run container in detached state.
- - 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
-
- # Ansible syntax check.
- - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
-
- # Test role.
- - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
+ # Download test shim.
+ - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/51ef4c5aea346b3f8dd2c2518233a70dac6407d9/ansible-role-test.sh
+ - chmod +x ${PWD}/tests/test.sh
- # Test role idempotence.
- - idempotence=$(mktemp)
- - docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- - >
- tail ${idempotence}
- | grep -q 'changed=0.*failed=0'
- && (echo 'Idempotence test: pass' && exit 0)
- || (echo 'Idempotence test: fail' && exit 1)
+ # Run tests.
+ - ${PWD}/tests/test.sh ${distro}
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
diff --git a/tasks/main.yml b/tasks/main.yml
index b0379a2..c5a4d7f 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -17,17 +17,8 @@
force: yes
when: ansible_os_family == 'Debian'
-- name: Install NTP (RedHat).
- yum: name=ntp state=installed
- when: ansible_os_family == 'RedHat'
-
-- name: Install NTP (Debian).
- apt: name=ntp state=installed
- when: ansible_os_family == 'Debian'
-
-- name: Install NTP (FreeBSD).
- pkgng: name=ntp state=present
- when: ansible_os_family == 'FreeBSD'
+- name: Install NTP.
+ package: name=ntp state=present
- name: Ensure NTP is running and enabled as configured.
service:
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..323a451
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,9 @@
+# Ansible Role tests
+
+To run the test playbook(s) in this directory:
+
+ 1. Install and start Docker.
+ 1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
+ - `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/51ef4c5aea346b3f8dd2c2518233a70dac6407d9/ansible-role-test.sh`
+ 1. Make the test shim executable: `chmod +x tests/test.sh`.
+ 1. Run (from the role root directory) `./tests/test.sh [distro] [optional - playbook]`