forked from CyVerse-Ansible/ansible-beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
213 lines (193 loc) · 13.5 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
sudo: required
services:
- docker
env:
- distribution: centos
version: 7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distribution: ubuntu
version: 14.04
init: /sbin/init
run_opts: ""
- distribution: ubuntu
version: 15.04
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distribution: ubuntu
version: 16.04
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
before_install:
# Pull image
- 'sudo docker pull ${distribution}:${version}'
# Customize Container
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
script:
- container_id=$(mktemp)
# Run container in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install cyverse.geoip'
## TEST: Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
###############################################
#### TEST: 1 - Topbeat
#### Execute the role with default values.
#### This will install topbeat.
###############################################
## Execute role with default values
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
- >
sudo docker exec "$(cat ${container_id})" topbeat -version
&& (echo 'Topbeat installed: pass' && exit 0)
|| (echo 'Topbeat not installed: fail' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/topbeat/topbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'topbeat.yml should not contain the text "DNE_TEST_ONLY": fail' && exit 1)
|| (echo 'topbeat.yml does not contain the text "DNE_TEST_ONLY": pass' && exit 0)
## Verify role idempotence.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
## Execute role with `beat_config` specified
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_config": {"input": {"period": 10, "procs": [".*"], "stats": {"system": true, "proc": true, "filesystem": true, "cpu_per_core": false}}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=2.*failed=0'
&& (echo 'Correct number of changes detected: pass' && exit 0)
|| (echo 'Wrong number of changes detected: fail' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/topbeat/topbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'topbeat.yml contains the text "DNE_TEST_ONLY": pass' && exit 0)
|| (echo 'topbeat.yml should contain the text "DNE_TEST_ONLY", but does not: fail' && exit 1)
## TEST: Test role idempotence - set config.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_config": {"input": {"period": 10, "procs": [".*"], "stats": {"system": true, "proc": true, "filesystem": true, "cpu_per_core": false}}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'
####################################################
#### TEST: 2 - Filebeat
#### Execute the role with `beat_name=filebeat`.
#### This will install filebeat.
####################################################
# Create new container, run in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install cyverse.geoip'
## Verify filebeat not installed
- >
sudo docker exec "$(cat ${container_id})" filebeat -version
&& (echo 'Filebeat installed: fail' && exit 1)
|| (echo 'Filebeat not installed: pass' && exit 0)
## Execute role with `beat_name=filebeat`
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=filebeat"'
## Verify filebeat installed
- >
sudo docker exec "$(cat ${container_id})" filebeat -version
&& (echo 'Filebeat installed' && exit 0)
|| (echo 'Filebeat not installed' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/filebeat/filebeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'filebeat.yml should not contain the text "DNE_TEST_ONLY": fail' && exit 1)
|| (echo 'filebeat.yml does not contain the text "DNE_TEST_ONLY": pass' && exit 0)
## Verify role idempotence - beat_name=filebeat.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=filebeat"
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
## Execute role with `beat_config` specified
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name": "filebeat", "beat_config": {"filebeat": {"prospectors": [{"paths": ["/var/log/*.log"], "input_type": "log"}]}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=2.*failed=0'
&& (echo 'Correct number of changes detected: pass' && exit 0)
|| (echo 'Wrong number of changes detected: fail' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/filebeat/filebeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'filebeat.yml contains the text "DNE_TEST_ONLY": pass' && exit 0)
|| (echo 'filebeat.yml should contain the text "DNE_TEST_ONLY", but does not: fail' && exit 1)
## TEST: Test role idempotence - set config.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name": "filebeat", "beat_config": {"filebeat": {"prospectors": [{"paths": ["/var/log/*.log"], "input_type": "log"}]}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'
####################################################
#### TEST: 3 - Packetbeat
#### Execute the role with `beat_name=packetbeat`.
#### This will install packetbeat.
####################################################
# Create new container, run in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install cyverse.geoip'
## Verify filebeat not installed
- >
sudo docker exec "$(cat ${container_id})" packetbeat -version
&& (echo 'Packetbeat installed: fail' && exit 1)
|| (echo 'Packetbeat not installed: pass' && exit 0)
## Execute role with `beat_name=packetbeat`
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=packetbeat"'
## Verify packetbeat installed
- >
sudo docker exec "$(cat ${container_id})" packetbeat -version
&& (echo 'Packetbeat installed' && exit 0)
|| (echo 'Packetbeat not installed' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/packetbeat/packetbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'packetbeat.yml should not contain the text "DNE_TEST_ONLY": fail' && exit 1)
|| (echo 'packetbeat.yml does not contain the text "DNE_TEST_ONLY": pass' && exit 0)
## Verify role idempotence - beat_name=packetbeat.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=packetbeat"
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
## Execute role with `beat_config` specified
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name": "packetbeat", "beat_config": {"interfaces": {"device": "any"}, "protocols": {"dns": {"ports": [35], "include_authorities": true, "include_additionals": true}, "http": {"ports": [80,8080,8000,5000,8002]}, "memcache": {"ports": [11211]}, "mysql": {"ports": [3306]}, "pgsql": {"ports": [5432]}, "redis": {"ports": [6379]}, "thrift": {"ports": [9090]}, "mongodb": {"ports": [27017]} }, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=2.*failed=0'
&& (echo 'Correct number of changes detected: pass' && exit 0)
|| (echo 'Wrong number of changes detected: fail' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/packetbeat/packetbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'packetbeat.yml contains the text "DNE_TEST_ONLY": pass' && exit 0)
|| (echo 'packetbeat.yml should contain the text "DNE_TEST_ONLY", but does not: fail' && exit 1)
## TEST: Test role idempotence - set config.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name": "packetbeat", "beat_config": {"interfaces": {"device": "any"}, "protocols": {"dns": {"ports": [35], "include_authorities": true, "include_additionals": true}, "http": {"ports": [80,8080,8000,5000,8002]}, "memcache": {"ports": [11211]}, "mysql": {"ports": [3306]}, "pgsql": {"ports": [5432]}, "redis": {"ports": [6379]}, "thrift": {"ports": [9090]}, "mongodb": {"ports": [27017]} }, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
#######################################################################
#### TEST: 3.1 - Packetbeat with geoip
#### Execute the role with `beat_name=packetbeat,beats_geoip`.
#### This will install allow the `cyverse.geoip` role to execute.
#######################################################################
- >
sudo docker exec "$(cat ${container_id})" ls /usr/share/GeoIP &>/dev/null
&& (echo 'This directory should not yet exist: fail' && exit 1)
|| (echo 'This directory does not yet exist: pass' && exit 0)
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=packetbeat beats_geoip=true"
- >
sudo docker exec "$(cat ${container_id})" ls /usr/share/GeoIP/GeoLiteCity.dat
&& (echo '/usr/share/GeoIP/GeoLiteCity.dat extracted: pass' && exit 0)
|| (echo '/usr/share/GeoIP/GeoLiteCity.dat not extracted: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
slack:
secure: x1vaxcEiiA/5Dv9r9zjvtMOES/MCI1qVIp7wsIH5xLNE+WMe38dqoJ0st5QGsmsAgMYu+U8HsWgy9p99lNxzMQBEcnv2uoHmFAUjFN4YEvRXf+E3liBE4kw9S2LPi866LjhKYrlH00IASe+wnhsVMnd64PCMd5B/LTytissr0TW7FcvTmmpcJfvNn4V9Mte3uZXtJ/GQB8hak0xyiuIMw8ODMXvoyHH0GpTNgrE9MOnXlynlK03D292bJArg7crAY+tDjjkGwa/HhGYlvkqfki85v3VAJllAyWPo1r959i4WQJ7E2Mvp9+KyciDmnLjhHrDa1aTW9Ah+gB542HFqyniwFur+H7E/eR+Sb2rg/v7Z5XGJWhigxcd3GPrqpjbkmRbZP0aAdV3eUNOMoBBfcNL0oz4n8rwvrbvcujuMFZzATd176pH7NLtSW5JuTFdPejRqpkUTOf6U6xmOg5sBVmbwuwc6QnT1mvvCrhI2E1ZsVs+PGz+EF1GYfUhMYKAHp65qRGlTsJHtQjDQpll/T94qm7I8bsrPKMs6BfeErY0pB2dM4+um3MliIorpBq/1aIyYdRz2pfXa626hpmNSGBEGatqCGTPbDvKGtm1mSbIHruZINxxSFtS6RJ7Vy5MTGS7iHTUfFtkmyJJBvpMtN2d3rBWlarVbddCM4NvRk+w=