mirror of
https://github.com/idealista/cookiecutter-ansible-role.git
synced 2024-11-23 19:07:00 +01:00
60 lines
2.4 KiB
YAML
60 lines
2.4 KiB
YAML
---
|
|
# This is an example playbook to execute goss tests.
|
|
# Tests need distributed to the appropriate ansible host/groups
|
|
# prior to execution by `goss validate`.
|
|
|
|
- name: Verify {{ cookiecutter.app_name | replace('_',' ') }}
|
|
hosts:
|
|
- {{ cookiecutter.app_name }}
|
|
become: true
|
|
vars:
|
|
goss_version: v0.3.16
|
|
goss_arch: amd64
|
|
goss_dst: /usr/local/bin/goss
|
|
goss_sha256sum: 827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb
|
|
goss_url: "https://github.com/goss-org/goss/releases/download/{% raw %}{{{% endraw %} goss_version {% raw %}}}{% endraw %}/goss-linux-{% raw %}{{{% endraw %} goss_arch {% raw %}}}{% endraw %}"
|
|
goss_test_directory: /tmp
|
|
goss_format: documentation
|
|
|
|
vars_files:
|
|
- ../../defaults/main.yml
|
|
|
|
tasks:
|
|
- name: Download and install Goss
|
|
get_url:
|
|
url: "{% raw %}{{{% endraw %} goss_url {% raw %}}}{% endraw %}"
|
|
dest: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %}"
|
|
checksum: "sha256{% raw %}:{{{% endraw %} goss_sha256sum {% raw %}}}{% endraw %}"
|
|
mode: 0755
|
|
register: download_goss
|
|
until: download_goss is succeeded
|
|
retries: 3
|
|
|
|
- name: Copy Goss tests to remote
|
|
template:
|
|
src: "{% raw %}{{{% endraw %} item {% raw %}}}{% endraw %}"
|
|
dest: "{% raw %}{{{% endraw %} goss_test_directory {% raw %}}}{% endraw %}/{% raw %}{{{% endraw %} item | basename {% raw %}}}{% endraw %}"
|
|
with_fileglob:
|
|
- "tests/test_*.yml"
|
|
|
|
- name: Register test files
|
|
shell: "ls {% raw %}{{{% endraw %} goss_test_directory {% raw %}}}{% endraw %}/test_*.yml"
|
|
register: test_files
|
|
|
|
- name: Execute Goss tests
|
|
command: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %} -g {% raw %}{{{% endraw %} item {% raw %}}}{% endraw %} validate --format {% raw %}{{{% endraw %} goss_format {% raw %}}}{% endraw %}"
|
|
register: test_results
|
|
with_items: "{% raw %}{{{% endraw %} test_files.stdout_lines {% raw %}}}{% endraw %}"
|
|
ignore_errors: true
|
|
|
|
- name: Display details about the Goss results
|
|
debug:
|
|
msg: "{% raw %}{{{% endraw %} item.stdout_lines {% raw %}}}{% endraw %}"
|
|
with_items: "{% raw %}{{{% endraw %} test_results.results {% raw %}}}{% endraw %}"
|
|
|
|
- name: Fail when tests fail
|
|
fail:
|
|
msg: "Goss failed to validate"
|
|
when: item.rc != 0
|
|
with_items: "{% raw %}{{{% endraw %} test_results.results {% raw %}}}{% endraw %}"
|