diff --git a/.travis.yml b/.travis.yml index 9ebde2e..e3e050b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,77 @@ ---- -language: python -python: "2.7" +sudo: required env: - - SITE=playbook.yml + global: + # https://github.com/travis-ci/travis-ci/issues/6461#issuecomment-239577306 + DOCKER_VERSION: "1.9.1-0~trusty" + matrix: + - distro: ernestasposkus/centos7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distro: ernestasposkus/centos6 + init: /sbin/init + run_opts: "" + - distro: ernestasposkus/ubuntu1604 + init: /lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distro: ernestasposkus/ubuntu1404 + init: /sbin/init + run_opts: "" -before_install: - - sudo apt-get update -qq - - sudo apt-get install curl -y +services: + - docker -install: - - pip install -U ansible +before_install: + # Downgrade to specific version of Docker engine. + - sudo apt-get update + - sudo apt-get remove docker-engine -yq + - sudo apt-get install docker-engine=$DOCKER_VERSION -yq --no-install-suggests --no-install-recommends --force-yes -o Dpkg::Options::="--force-confnew" - # Add ansible.cfg to pick up roles path. - - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" + # Pull container. + - 'sudo docker pull ${distro}:latest' script: - # Check the role/playbook's syntax. - - "ansible-playbook -i tests/inventory tests/$SITE --syntax-check" + - container_id=$(mktemp) + # Run container in detached state. + - 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distro}:latest "${init}" > "${container_id}"' + + # Inspect docker container + - 'sudo docker inspect $(cat ${container_id})' + + # Print ansible version + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible --version' + + # Check Ansible host setup + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible all -i "localhost," -c local -m setup' + + # Install dependencies + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-galaxy install geerlingguy.java' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-galaxy install AnsibleShipyard.ansible-zookeeper' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/dependencies.yml' + + # Ansible syntax check. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml --syntax-check' + + # Test role. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml' + + # Test role idempotence. + - idempotence=$(mktemp) + - sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml | tee -a ${idempotence} + - > + tail ${idempotence} + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) + + # Test role. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml' + + # View container logs + - 'sudo docker logs "$(cat ${container_id})"' - # Run the role/playbook with ansible-playbook. - - "ansible-playbook -i tests/inventory tests/playbook.yml --connection=local --sudo" + # Clean up. + - 'sudo docker stop "$(cat ${container_id})"' - # Healthcheck - # - "curl http://localhost:5050/" +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ - "curl http://localhost:5050/" diff --git a/defaults/main.yml b/defaults/main.yml index 63b5316..154efba 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,9 +1,9 @@ --- mesos_install_mode: "master" # {master|slave|master-slave} -mesos_version: "0.25.0" +mesos_version: "1.0.1" # Debian -mesos_package_version: "0.2.70" +mesos_package_version: "2.0.93" mesosphere_apt_url: "http://repos.mesosphere.com/{{ ansible_distribution | lower }}" mesos_os_distribution: "{{ ansible_distribution | lower }}" mesos_os_version: "{{ ansible_distribution_version.split('.') | join('') }}" diff --git a/handlers/main.yml b/handlers/main.yml index f574250..c5a079c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,12 +3,13 @@ # While waiting for https://github.com/ansible/ansible-modules-core/issues/191 - name: Reload daemon command: systemctl daemon-reload - + when: ansible_service_mgr == 'systemd' + # i.e. upgrade mesos, templates stay the same... - name: Restart mesos-master service: name=mesos-master state=restarted when: mesos_install_mode == "master" or mesos_install_mode == "master-slave" -- name: Restart mesos-slave +- name: Restart mesos-slave service: name=mesos-slave state=restarted when: mesos_install_mode == "slave" or mesos_install_mode == "master-slave" diff --git a/tasks/mesos.yml b/tasks/mesos.yml index 4186887..728ef6c 100644 --- a/tasks/mesos.yml +++ b/tasks/mesos.yml @@ -35,35 +35,35 @@ notify: - Restart mesos-slave -- name: Check if upstart exists - stat: path=/etc/init/ - register: etc_init - - name: Mesos master upstart script template: src=init-mesos-master.j2 dest=/etc/init/mesos-master.conf - when: (mesos_install_mode == "master" or mesos_install_mode == "master-slave") and etc_init.stat.exists == true + when: + - (mesos_install_mode == "master" or mesos_install_mode == "master-slave") + - ansible_service_mgr != 'systemd' notify: - Restart mesos-master - name: Mesos slave upstart script template: src=init-mesos-slave.j2 dest=/etc/init/mesos-slave.conf - when: (mesos_install_mode == "slave" or mesos_install_mode == "master-slave") and etc_init.stat.exists == true + when: + - (mesos_install_mode == "slave" or mesos_install_mode == "master-slave") + - ansible_service_mgr != 'systemd' notify: - Restart mesos-slave - + - name: Check if systemd exists - stat: path=/usr/lib/systemd/system/ + stat: path=/lib/systemd/system/ register: systemd_check - + - name: Mesos master systemd script - template: src=mesos-master.service.j2 dest=/usr/lib/systemd/system/mesos-master.service + template: src=mesos-master.service.j2 dest=/lib/systemd/system/mesos-master.service when: (mesos_install_mode == "master" or mesos_install_mode == "master-slave") and systemd_check.stat.exists == true notify: - Reload daemon - Restart mesos-master - name: Mesos slave systemd script - template: src=mesos-slave.service.j2 dest=/usr/lib/systemd/system/mesos-slave.service + template: src=mesos-slave.service.j2 dest=/lib/systemd/system/mesos-slave.service when: (mesos_install_mode == "slave" or mesos_install_mode == "master-slave") and systemd_check.stat.exists == true notify: - Reload daemon diff --git a/tests/dependencies.yml b/tests/dependencies.yml new file mode 100644 index 0000000..caee066 --- /dev/null +++ b/tests/dependencies.yml @@ -0,0 +1,7 @@ +--- +- hosts: localhost + connection: local + remote_user: root + roles: + - role: geerlingguy.java + - role: AnsibleShipyard.ansible-zookeeper diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 8bb7ba6..0000000 --- a/tests/inventory +++ /dev/null @@ -1,2 +0,0 @@ -[local] -localhost diff --git a/tests/main.yml b/tests/main.yml deleted file mode 100644 index 547a98a..0000000 --- a/tests/main.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- hosts: localhost - connection: local - sudo: yes - - tasks: - - name: Wait for Mesosphere to be up - wait_for: host="{{ansible_default_ipv4.address}}" port=5050 state=started delay=3 timeout=5 - - - name: Test for Mesosphere metrics endpoint - get_url: - url="http://{{ansible_default_ipv4.address}}:5050/metrics/snapshot" - dest=/tmp/mesos-metrics - force=yes - register: status - failed_when: "'OK' not in status.msg" - diff --git a/tests/playbook.yml b/tests/playbook.yml index adb4810..b578bff 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,14 +1,7 @@ --- -# -# Test Playbook -# - - hosts: localhost connection: local - sudo: yes - + remote_user: root roles: - - {role: ../../, mesos_install_mode: "master-slave"} - -- include: main.yml - + - role: role_under_test + mesos_install_mode: "master-slave" diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..dd72ec2 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,14 @@ +--- +- hosts: localhost + connection: local + remote_user: root + tasks: + - shell: "ps aux | grep -i mesos" + register: status + failed_when: status.rc != 0 + when: ansible_service_mgr != 'systemd' + + - shell: "systemctl status mesos-master | grep running" + register: status + failed_when: status.rc != 0 + when: ansible_service_mgr == 'systemd'