-
Notifications
You must be signed in to change notification settings - Fork 34
/
verify.yml
93 lines (84 loc) · 2.9 KB
/
verify.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
---
# Molecule Goss Tests
- name: Verify
hosts: all
become: true
vars:
goss_version: v0.3.10
goss_arch: amd64
goss_bin: /usr/local/bin/goss
goss_sha256sum: 150f25495ca0d1d4fd2ef8d0e750dbd767a15e9a522505f99b61dd1dd40a76d4
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /tmp/molecule/goss
goss_format: documentation
tasks:
- name: Download and install Goss
ansible.builtin.get_url:
url: "{{ goss_url }}"
dest: "{{ goss_bin }}"
sha256sum: "{{ goss_sha256sum }}" # noqa: args[module]
mode: "u=rwx,go=rx"
register: download_goss
until: download_goss is succeeded
retries: 3
- name: Create Molecule directory for test files
ansible.builtin.file:
path: "{{ goss_test_directory }}"
state: directory
mode: "0755"
- name: Find Goss tests on localhost
ansible.builtin.find:
paths: "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}"
patterns:
- "test[-.\\w]*.yml"
- "test_host_{{ ansible_hostname }}[-.\\w]*.yml"
excludes:
- "test_host_(?!{{ ansible_hostname }})[-.\\w]*.yml"
use_regex: true
delegate_to: localhost
register: test_files
changed_when: false
become: false
- name: Debug
ansible.builtin.debug:
msg: "{{ test_files.files }}"
verbosity: 3
- name: Copy Goss tests to remote
ansible.builtin.copy:
src: "{{ item.path }}"
dest: "{{ goss_test_directory }}/{{ item.path | basename }}"
mode: "0644"
with_items:
- "{{ test_files.files }}"
loop_control:
label: "{{ item.path | basename }}"
- name: Register test files
ansible.builtin.find:
paths:
- "{{ goss_test_directory }}"
patterns:
- "test_*.yml"
register: test_files
- name: Run verify
when: test_files is succeeded
block:
- name: Execute Goss tests # noqa: no-changed-when
ansible.builtin.command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}"
register: test_results
with_items: "{{ test_files.files | map(attribute='path') | list }}"
loop_control:
label: "{{ item | basename }}"
failed_when: false
- name: Display details about the Goss results
ansible.builtin.debug:
msg: "{{ item.stdout_lines }}"
with_items: "{{ test_results.results }}"
loop_control:
label: "{{ item[item.ansible_loop_var] | basename }}"
- name: Fail when tests fail
ansible.builtin.fail:
msg: "Goss failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"
loop_control:
label: "{{ item[item.ansible_loop_var] | basename }}"