2023-04-28 00:32:36 +02:00
|
|
|
---
|
|
|
|
# This is an example playbook to execute goss tests.
|
|
|
|
# Tests need distributed to the appropriate ansible host/groups
|
|
|
|
# prior to execution by `goss validate`.
|
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Verify sonarqube"
|
2023-04-28 00:32:36 +02:00
|
|
|
hosts:
|
2023-04-29 20:48:33 +02:00
|
|
|
- "sonarqube"
|
2023-04-28 00:32:36 +02:00
|
|
|
become: true
|
|
|
|
vars:
|
2023-04-29 20:48:33 +02:00
|
|
|
goss_version: "v0.3.16"
|
|
|
|
goss_arch: "amd64"
|
|
|
|
goss_dst: "/usr/local/bin/goss"
|
|
|
|
goss_sha256sum: "827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb"
|
2023-04-28 00:32:36 +02:00
|
|
|
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
|
2023-04-29 20:48:33 +02:00
|
|
|
goss_test_directory: "/tmp"
|
|
|
|
goss_format: "documentation"
|
2023-04-28 00:32:36 +02:00
|
|
|
|
|
|
|
vars_files:
|
2023-04-29 20:48:33 +02:00
|
|
|
- "../../defaults/main.yml"
|
2023-04-28 00:32:36 +02:00
|
|
|
|
|
|
|
tasks:
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Download and install Goss"
|
2023-04-28 00:32:36 +02:00
|
|
|
get_url:
|
|
|
|
url: "{{ goss_url }}"
|
|
|
|
dest: "{{ goss_dst }}"
|
|
|
|
checksum: "sha256:{{ goss_sha256sum }}"
|
|
|
|
mode: 0755
|
2023-04-29 20:48:33 +02:00
|
|
|
register: "download_goss"
|
|
|
|
until: "download_goss is succeeded"
|
2023-04-28 00:32:36 +02:00
|
|
|
retries: 3
|
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Copy Goss tests to remote"
|
2023-04-28 00:32:36 +02:00
|
|
|
template:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "{{ goss_test_directory }}/{{ item | basename }}"
|
|
|
|
with_fileglob:
|
|
|
|
- "tests/test_*.yml"
|
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Register test files"
|
2023-04-28 00:32:36 +02:00
|
|
|
shell: "ls {{ goss_test_directory }}/test_*.yml"
|
2023-04-29 20:48:33 +02:00
|
|
|
register: "test_files"
|
2023-04-28 00:32:36 +02:00
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Execute Goss tests"
|
2023-04-28 00:32:36 +02:00
|
|
|
command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}"
|
2023-04-29 20:48:33 +02:00
|
|
|
register: "test_results"
|
2023-04-28 00:32:36 +02:00
|
|
|
with_items: "{{ test_files.stdout_lines }}"
|
|
|
|
ignore_errors: true
|
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Display details about the Goss results"
|
2023-04-28 00:32:36 +02:00
|
|
|
debug:
|
|
|
|
msg: "{{ item.stdout_lines }}"
|
|
|
|
with_items: "{{ test_results.results }}"
|
|
|
|
|
2023-04-29 20:48:33 +02:00
|
|
|
- name: "Fail when tests fail"
|
2023-04-28 00:32:36 +02:00
|
|
|
fail:
|
|
|
|
msg: "Goss failed to validate"
|
2023-04-29 20:48:33 +02:00
|
|
|
when: "item.rc != 0"
|
2023-04-28 00:32:36 +02:00
|
|
|
with_items: "{{ test_results.results }}"
|