Skip to content

Commit 359bbda

Browse files
committed
verification
1 parent a0a4e6c commit 359bbda

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

molecule/default/tests/test_default.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Molecule managed
2+
3+
---
4+
package:
5+
git:
6+
installed: true

molecule/default/verify.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
# This is an example playbook to execute goss tests.
3+
# Tests need distributed to the appropriate ansible host/groups
4+
# prior to execution by `goss validate`.
5+
6+
- name: Verify
7+
hosts: all
8+
become: true
9+
vars:
10+
goss_version: v0.3.7
11+
goss_arch: amd64
12+
goss_dst: /usr/local/bin/goss
13+
# yamllint disable-line rule:line-length
14+
goss_sha256sum: 357f5c7f2e7949b412bce44349cd32ab19eb3947255a8ac805f884cc2c326059
15+
# yamllint disable-line rule:line-length
16+
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
17+
goss_test_directory: /tmp
18+
goss_format: tap
19+
tasks:
20+
- name: Download and install Goss
21+
get_url:
22+
url: "{{ goss_url }}"
23+
dest: "{{ goss_dst }}"
24+
sha256sum: "{{ goss_sha256sum }}"
25+
mode: 0755
26+
register: download_goss
27+
until: download_goss is succeeded
28+
retries: 3
29+
30+
- name: Copy Goss tests to remote
31+
copy:
32+
src: "{{ item }}"
33+
dest: "{{ goss_test_directory }}/{{ item | basename }}"
34+
mode: 0644
35+
with_fileglob:
36+
- "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml"
37+
38+
- name: Register test files
39+
shell: "ls {{ goss_test_directory }}/test_*.yml"
40+
changed_when: false
41+
register: test_files
42+
43+
- name: Execute Goss tests
44+
environment:
45+
# yamllint disable-line rule:line-length
46+
PATH: '/opt/rh/rh-git218/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
47+
command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}"
48+
changed_when: false
49+
register: test_results
50+
with_items: "{{ test_files.stdout_lines }}"
51+
52+
- name: Display details about the Goss results
53+
debug:
54+
msg: "{{ item.stdout_lines }}"
55+
with_items: "{{ test_results.results }}"
56+
57+
- name: Fail when tests fail
58+
fail:
59+
msg: "Goss failed to validate"
60+
when: item.rc != 0
61+
with_items: "{{ test_results.results }}"

0 commit comments

Comments
 (0)