cookiecutter-ansible-role-d.../ansible-role-{{cookiecutter.app_name}}/molecule/default/verify.yml

60 lines
2.7 KiB
YAML
Raw Permalink Normal View History

2020-04-28 13:23:10 +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`.
- name: Verify {{ cookiecutter.app_name | replace('_',' ') }}
hosts:
2023-04-30 13:07:53 +02:00
- "{{ cookiecutter.app_name }}"
2020-04-28 13:23:10 +02:00
become: true
vars:
2023-04-30 13:07:53 +02:00
goss_version: "v0.3.16"
goss_arch: "amd64"
goss_dst: "/usr/local/bin/goss"
goss_sha256sum: "827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb"
2020-04-28 13:23:10 +02:00
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{% raw %}{{{% endraw %} goss_version {% raw %}}}{% endraw %}/goss-linux-{% raw %}{{{% endraw %} goss_arch {% raw %}}}{% endraw %}"
2023-04-30 13:07:53 +02:00
goss_test_directory:" /tmp"
goss_format: "documentation"
2020-04-28 13:23:10 +02:00
vars_files:
- ../../defaults/main.yml
tasks:
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Download and install Goss"
2020-04-28 13:23:10 +02:00
get_url:
url: "{% raw %}{{{% endraw %} goss_url {% raw %}}}{% endraw %}"
dest: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %}"
checksum: "sha256{% raw %}:{{{% endraw %} goss_sha256sum {% raw %}}}{% endraw %}"
2020-04-28 13:23:10 +02:00
mode: 0755
2023-04-30 13:07:53 +02:00
register: "download_goss"
until: "download_goss is succeeded"
2020-04-28 13:23:10 +02:00
retries: 3
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Copy Goss tests to remote"
2020-04-28 13:23:10 +02:00
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"
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Register test files"
2020-04-28 13:23:10 +02:00
shell: "ls {% raw %}{{{% endraw %} goss_test_directory {% raw %}}}{% endraw %}/test_*.yml"
2023-04-30 13:07:53 +02:00
register: "test_files"
2020-04-28 13:23:10 +02:00
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Execute Goss tests"
2020-04-28 13:23:10 +02:00
command: "{% raw %}{{{% endraw %} goss_dst {% raw %}}}{% endraw %} -g {% raw %}{{{% endraw %} item {% raw %}}}{% endraw %} validate --format {% raw %}{{{% endraw %} goss_format {% raw %}}}{% endraw %}"
2023-04-30 13:07:53 +02:00
register: "test_results"
2020-04-28 13:23:10 +02:00
with_items: "{% raw %}{{{% endraw %} test_files.stdout_lines {% raw %}}}{% endraw %}"
ignore_errors: true
2020-04-28 13:23:10 +02:00
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Display details about the Goss results"
2020-04-28 13:23:10 +02:00
debug:
msg: "{% raw %}{{{% endraw %} item.stdout_lines {% raw %}}}{% endraw %}"
with_items: "{% raw %}{{{% endraw %} test_results.results {% raw %}}}{% endraw %}"
2023-04-30 13:07:53 +02:00
- name: "{{ cookiecutter.app_name | upper }} | Fail when tests fail"
2020-04-28 13:23:10 +02:00
fail:
msg: "Goss failed to validate"
when: item.rc != 0
2020-11-11 16:51:24 +01:00
with_items: "{% raw %}{{{% endraw %} test_results.results {% raw %}}}{% endraw %}"