forked from willshersystems/ansible-sshd
-
Notifications
You must be signed in to change notification settings - Fork 5
/
.travis.yml
120 lines (98 loc) · 5.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
---
os: linux
dist: focal
language: python
addons:
apt_packages:
- yamllint
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
before_install:
- sudo -H pip3 install ansible
install:
# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; echo 'deprecation_warnings=False'; } >> ansible.cfg"
script:
# Test 0a: Check the roles syntax.
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_default.yml --syntax-check"
# Test 0b: Run yamllint with galaxy configuration to avoid quality score penalty
- wget https://raw.githubusercontent.com/ansible/galaxy/devel/galaxy/importer/linters/yamllint.yaml
- "yamllint -c yamllint.yaml **/*.yml"
# Test 0.5: OS defaults: Travis images have heavily updated (even with invalid configuration options)
# sshd_config so it does not make sense to test OS defaults here
# Test 1a: Run the role
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_default.yml --connection=local --become -v"
# Test 1b: Run the role through include (skipping backup)
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_default_include.yml -e sshd_test_backup_skip=yes --connection=local --become -v"
# Test 2: Run the role/playbook again, checking to make sure it's idempotent (skipping backup)
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_default.yml --connection=local -e sshd_test_backup_skip=yes --become | grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Test 3: Check we can set arbitrary configuration options
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_set_common.yml --connection=local --become -v
&& (echo 'Common variables test: pass' && exit 0)
|| (echo 'Common variables test: fail' && exit 1)
# Test 4: Check if we set uncommon or unsupported configuration option, it will not fail hard
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_set_uncommon.yml --connection=local --become -v
&& (echo 'Uncommon configuration test: pass' && exit 0)
|| (echo 'Uncommon configuration test: fail' && exit 1)
# Test 5a: Make sure we can modify other files, for example for inclusion
# in the main sshd_config or second sshd service
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_alternative_file.yml --connection=local --become -v
&& (echo 'Alternative configuration file test: pass' && exit 0)
|| (echo 'Alternative configuration file test: fail' && exit 1)
# Test 5b: Make sure we can modify other files, for example for inclusion
# in the main sshd_config or second sshd service using the old invocation
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_alternative_file_role.yml --connection=local --become -v
&& (echo 'Alternative configuration file role test: pass' && exit 0)
|| (echo 'Alternative configuration file role test: fail' && exit 1)
# Test 6: Test match blocks generators
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_match.yml --connection=local --become -v
&& (echo 'Match blocks test: pass' && exit 0)
|| (echo 'Match blocks test: fail' && exit 1)
# Test 7: Test match blocks generators with iteration
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_match_iterate.yml --connection=local --become -v
&& (echo 'Match blocks with iteration test: pass' && exit 0)
|| (echo 'Match blocks with iteration test: fail' && exit 1)
# Test 8a: Test hostkeys can be generated by this role
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_hostkeys.yml --connection=local --become -v
&& (echo 'Hostkeys test: pass' && exit 0)
|| (echo 'Hostkeys test: fail' && exit 1)
# Test 8b: Test hostkeys can be generated by this role using old invocation
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_hostkeys_role.yml --connection=local --become -v
&& (echo 'Hostkeys role test: pass' && exit 0)
|| (echo 'Hostkeys role test: fail' && exit 1)
# Test 9: Test missing hostkeys
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_hostkeys_missing.yml --connection=local --become -v
&& (echo 'Missing hostkeys test: pass' && exit 0)
|| (echo 'Missing hostkeys test: fail' && exit 1)
# Test 10: Test sshd_enable has effect
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_sshd_enable.yml --connection=local --become -v
&& (echo 'Test sshd_enable: pass' && exit 0)
|| (echo 'Test sshd_enable: fail' && exit 1)
# Test 11: Test variable precedence
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_precedence.yml --connection=local --become -v
&& (echo 'Variable precedence test: pass' && exit 0)
|| (echo 'Variable precedence test: fail' && exit 1)
# Test 12: Verify backups are created
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_backup.yml --connection=local --become -v
&& (echo 'Backup test: pass' && exit 0)
|| (echo 'Backup test: fail' && exit 1)
# Test 13: Verify configuration namespace
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/tests_config_namespace.yml --connection=local --become -v
&& (echo 'Namespace test: pass' && exit 0)
|| (echo 'Namespace test: fail' && exit 1)