From 19dfa1942bb7452c4006055b69b5f0ac031f0ae7 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 9 May 2014 09:44:06 -0500 Subject: Add Travis integration for real. --- .travis.yml | 30 ++++++++++++++++++++++++++++++ defaults/main.yml | 3 +++ tasks/main.yml | 9 ++++++++- tests/inventory | 1 + tests/test.yml | 5 +++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 defaults/main.yml create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3eee176 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +--- +language: python +python: "2.7" + +env: + - SITE=test.yml + +before_install: + - sudo apt-get update -qq + +install: + # Install Ansible. + - pip install ansible==1.5.0 + + # Add ansible.cfg to pick up roles path. + - "printf '[defaults]\nroles_path = ../' > ansible.cfg" + +script: + # Check the role/playbook's syntax. + - "ansible-playbook -i tests/inventory tests/$SITE --syntax-check" + + # Run the role/playbook with ansible-playbook. + - "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo" + + # Run the role/playbook again, checking to make sure it's idempotent. + - > + ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..f0fc211 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +--- +ntp_enabled: true +ntp_timezone: America/Chicago diff --git a/tasks/main.yml b/tasks/main.yml index 144c455..8ee5d87 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,9 +13,16 @@ apt: name=ntp state=installed when: ansible_os_family == 'Debian' -- name: Ensure NTP is running. +- name: Ensure NTP is running and enabled at system start. service: > name={{ ntp_daemon }} state=started enabled=yes when: ntp_enabled + +- name: Ensure NTP is stopped and disabled at system start. + service: > + name={{ ntp_daemon }} + state=stopped + enabled=no + when: !ntp_enabled diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..9093df7 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-role-ntp -- cgit v1.2.3