-
Notifications
You must be signed in to change notification settings - Fork 1
/
.travis.yml
109 lines (92 loc) · 4.21 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
# We need sudo for some of the Docker commands.
sudo: required
env:
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro --volume=/tmp:/tmp:rw --volume=/run:/run:rw"
- distro: centos6
init: /sbin/init
run_opts: ""
# - distro: fedora24
# init: /usr/sbin/init
# run_opts: "--volume=/sys/fs/cgroup:/sys/fs/cgroup:ro --volume=/tmp:/tmp:rw --volume=/run:/run:rw"
- distro: debian9
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: debian8
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# - distro: ubuntu1404
# init: /lib/systemd/systemd
# run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# Tell Travis to start Docker when it brings up an environment.
services:
- docker
before_install:
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
script:
- sudo apt-get install -y sshpass
- container_id=$(mktemp)
# Run container in detached state.
- 'docker run --detach -p 22 --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
# Apparently, we need to run apt-get update for Ubuntu before we test our role
- 'if [ ${distro} = "ubuntu1604" ]; then docker exec --tty "$(cat ${container_id})" env TERM=xterm apt-get update; fi'
# Test facts.
#- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible -m setup localhost'
# 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'
# 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)
# Other tests if necessary
# Check if sshd is started
# - ssh=$(mktemp)
# - docker exec "$(cat ${container_id})" env TERM=xterm ps -eaf | tee -a ${ssh}
# - >
# tail ${ssh}
# | grep -q "/usr/sbin/sshd"
# && (echo 'SSH is started - success' && exit 0)
# || (echo 'SSH is not started - failure' && exit 1)
# Test assertions.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-assertions.yml'
# Check if configuration has been put into place
# - ssh_config=$(mktemp)
# - docker exec "$(cat ${container_id})" env TERM=xterm cat /etc/ssh/sshd_config | tee -a ${ssh_config}
# - >
# tail ${ssh_config}
# | grep -q "PermitRootLogin.*without-password"
# && (echo 'Configuration - success' && exit 0)
# || (echo 'Configuraiton - not successful' && exit 1)
# Actually test whether or not an SSH connection works
#- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm useradd --password "$6$fr/j/P.8$gudGkPvtlJVPnzdVIRXa7pjqSYvHOg5wGDM5/jGkgY1wQNehvx3qN/DGLNLz9sAj8RauNa2gPvFiISnPivWSq/" test'
#- >
# sshpass -p 'test' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no test@localhost date
# && (echo 'SSH test: pass' && exit 0)
# || (echo 'SSH test: fail' && exit 1)
#after_failure:
# # Check what happened on systemd systems.
# - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm systemctl -l status ${service_name}'
# - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm journalctl -xe --no-pager'
notifications:
email: false
irc:
channels:
- "chat.freenode.net#isudevops"
on_success: always
on_failure: change
use_notice: true
template:
- "%{repository_name}#%{build_number} [%{author}] (%{commit}): %{message} %{foo} "
- "Build details: %{build_url}"
webhooks: https://galaxy.ansible.com/api/v1/notifications/