-
Notifications
You must be signed in to change notification settings - Fork 26
/
.gitlab-ci.yml
67 lines (59 loc) · 2.36 KB
/
.gitlab-ci.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
### Environments
test_centos7:
<<: *test_definition
variables:
DOCKER_IMAGE: geerlingguy/docker-centos7-ansible:latest
DOCKER_INIT: /usr/lib/systemd/systemd
DOCKER_RUN_OPTS: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
DOCKER_NAME: "gitlab-ci-$CI_BUILD_ID-$CI_BUILD_REF"
test_centos6:
<<: *test_definition
variables:
DOCKER_IMAGE: geerlingguy/docker-centos6-ansible:latest
DOCKER_INIT: /sbin/init
DOCKER_RUN_OPTS: ""
DOCKER_NAME: "gitlab-ci-$CI_BUILD_ID-$CI_BUILD_REF"
test_ubuntu1604:
<<: *test_definition
variables:
DOCKER_IMAGE: geerlingguy/docker-ubuntu1604-ansible:latest
DOCKER_INIT: /lib/systemd/systemd
DOCKER_RUN_OPTS: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
DOCKER_NAME: "gitlab-ci-$CI_BUILD_ID-$CI_BUILD_REF"
test_ubuntu1404:
<<: *test_definition
variables:
DOCKER_IMAGE: geerlingguy/docker-ubuntu1404-ansible:latest
DOCKER_INIT: /sbin/init
DOCKER_RUN_OPTS: ""
DOCKER_NAME: gitlab-ci-$CI_BUILD_ID-$CI_BUILD_REF
### Test template
.test_template: &test_definition
variables:
- DOCKER_NAME: "gitlab-ci-$CI_BUILD_ID-$CI_BUILD_REF"
before_script:
- docker pull $DOCKER_IMAGE
script:
- docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro --name $DOCKER_NAME $DOCKER_RUN_OPTS $DOCKER_IMAGE $DOCKER_INIT
# Ansible sytax check
- docker exec $DOCKER_NAME ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check
# Test role
- docker exec $DOCKER_NAME ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml
# Test role idempotence
- idempotence=$(mktemp)
- docker exec $DOCKER_NAME 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)
# Test role
- docker exec $DOCKER_NAME ansible-playbook /etc/ansible/roles/role_under_test/tests/test_with_webserver.yml
- docker exec -d $DOCKER_NAME python /opt/py-httpd.py
- docker exec $DOCKER_NAME curl -o /dev/null https://localhost && (echo 'Test SSL Passed' && exit 0) || (echo 'Test SSL Failed' && exit 1)
after_script:
- docker kill $DOCKER_NAME
- docker rm $DOCKER_NAME
### Stages/ Jobs Section
stages:
- test