Skip to content

Commit

Permalink
Features/introduce multi platform travis (#45)
Browse files Browse the repository at this point in the history
* Remove dockefiles directory

* Remove ci directory

* Check for ansible_service_mgr when installing services

* Remove recurse directive when creating directories

* Add new .travis and tests

* Install systemd unit file under /lib/systemd/system

* Reload systemctl daemon when systemd
  • Loading branch information
ernestas-poskus authored Sep 12, 2016
1 parent 5b91acf commit 9487315
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 179 deletions.
83 changes: 65 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
---
language: python
python: "2.7"
sudo: required

before_install:
- sudo apt-get update -qq
- sudo apt-get install curl -y
env:
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: ""

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 ci/inventory ci/playbook.yml --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-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)
# Run the ansible ci playbook
- "ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv"
# Test role.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'

# Run the ansible hosts list
- "ansible-playbook -i ci/inventory ci/hosts_list.yml --connection=local --sudo -vvvv"
# View container logs
- 'sudo docker logs "$(cat ${container_id})"'

# Run the ansible hosts hash
- "ansible-playbook -i ci/inventory ci/hosts_hash.yml --connection=local --sudo -vvvv"
# Clean up.
- 'sudo docker stop "$(cat ${container_id})"'

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
23 changes: 0 additions & 23 deletions ci/hosts_hash.yml

This file was deleted.

22 changes: 0 additions & 22 deletions ci/hosts_list.yml

This file was deleted.

2 changes: 0 additions & 2 deletions ci/inventory

This file was deleted.

13 changes: 0 additions & 13 deletions ci/playbook.yml

This file was deleted.

13 changes: 0 additions & 13 deletions ci/tests.yml

This file was deleted.

37 changes: 0 additions & 37 deletions dockerfiles/centos/Dockerfile

This file was deleted.

37 changes: 0 additions & 37 deletions dockerfiles/ubuntu/Dockerfile

This file was deleted.

4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
- name: Restart zookeeper
service: name=zookeeper state=restarted

- name: Reload systemctl daemon
command: systemctl daemon-reload
when: ansible_service_mgr == 'systemd'
9 changes: 3 additions & 6 deletions tasks/systemd.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---
- name: Check if systemd exists
stat: path=/usr/lib/systemd/system/
register: systemd_check

- name: Systemd script.
template: src=zookeeper.service.j2 dest=/usr/lib/systemd/system/zookeeper.service
when: systemd_check.stat.exists == true
template: src=zookeeper.service.j2 dest=/lib/systemd/system/zookeeper.service
when: ansible_service_mgr == 'systemd'
notify:
- Reload systemctl daemon
- Restart zookeeper
13 changes: 6 additions & 7 deletions tasks/tarball.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
- user: name=zookeeper group=zookeeper system=yes

- name: Change ownership on zookeeper directory.
file: path={{zookeeper_dir}} state=directory owner=zookeeper group=zookeeper recurse=yes
file: path={{zookeeper_dir}} state=directory owner=zookeeper group=zookeeper
tags: bootstrap

- name: Create zookeeper data folder.
file: path={{data_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper
tags: bootstrap

- name: Create zookeeper logs folder.
file: path={{log_dir}} state=directory recurse=yes owner=zookeeper group=zookeeper
- name: "Create zookeeper {{item}} directory."
file: path={{item}} state=directory owner=zookeeper group=zookeeper
tags: bootstrap
with_items:
- "{{data_dir}}"
- "{{log_dir}}"

- name: Write myid file.
template: src=myid.j2 dest={{data_dir}}/myid owner=zookeeper group=zookeeper
Expand Down
4 changes: 3 additions & 1 deletion tasks/upstart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

- name: Upstart script.
template: src=zookeeper.conf.j2 dest=/etc/init/zookeeper.conf
when: etc_init.stat.exists == true
when:
- etc_init.stat.exists == true
- ansible_service_mgr != 'systemd'
notify:
- Restart zookeeper
6 changes: 6 additions & 0 deletions tests/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- hosts: localhost
connection: local
remote_user: root
roles:
- role: geerlingguy.java
6 changes: 6 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- hosts: localhost
connection: local
remote_user: root
roles:
- role: role_under_test
57 changes: 57 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- hosts: localhost
connection: local
remote_user: root
tasks:
- shell: "ps aux | grep -i zookeeper"
register: status
failed_when: status.rc != 0
when: ansible_service_mgr != 'systemd'

- shell: "systemctl status zookeeper | grep running"
register: status
failed_when: status.rc != 0
when: ansible_service_mgr == 'systemd'

#
# Host hash playbook
#

- hosts: localhost
connection: local
remote_user: root
roles:
- role: role_under_test
zookeeper_hosts:
- host: "{{inventory_hostname}}" # the machine running
id: 2

- hosts: localhost
connection: local
remote_user: root
tasks:
# Expecting myid to be 2 as defined in zookeeper_hosts variable
- shell: "grep 2 /var/lib/zookeeper/myid"
register: status
failed_when: status.rc != 0

#
# Host list playbook
#

- hosts: localhost
connection: local
remote_user: root
roles:
- role: role_under_test
zookeeper_hosts:
- "{{inventory_hostname}}"

- hosts: localhost
connection: local
remote_user: root
tasks:
# Expecting myid to be 1 defined by loop.index
- shell: "grep 1 /var/lib/zookeeper/myid"
register: status
failed_when: status.rc != 0

0 comments on commit 9487315

Please sign in to comment.