From 37eb692cea129892953cb6ef6e13703975ab05c2 Mon Sep 17 00:00:00 2001 From: Norbert Varzariu Date: Wed, 2 Jan 2019 17:49:21 +0100 Subject: [PATCH] update goss verify.yml to allow to pass host to run on Signed-off-by: Norbert Varzariu --- .../{{cookiecutter.scenario_name}}/verify.yml | 38 ++++++++++++------- .../verifier/molecule/goss/verify.yml | 20 +++++++++- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/molecule/cookiecutter/scenario/verifier/goss/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/verify.yml b/molecule/cookiecutter/scenario/verifier/goss/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/verify.yml index d9c59713cc..61baa5eb07 100644 --- a/molecule/cookiecutter/scenario/verifier/goss/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/verify.yml +++ b/molecule/cookiecutter/scenario/verifier/goss/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/verify.yml @@ -8,39 +8,51 @@ hosts: all become: true vars: - goss_version: v0.3.6 + goss_version: v0.2.5 goss_arch: amd64 - goss_dst: /usr/local/bin/goss - goss_sha256sum: 53dd1156ab66f2c4275fd847372e6329d895cfb2f0bcbec5f86c1c4df7236dde - goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" - goss_test_directory: /tmp + goss_bin: /usr/local/bin/goss + goss_sha256sum: 31d04f98444ded26e2478fbdb3f5949cc9318bed13b5937598facc1818e1fce1. + goss_test_directory: /tmp/molecule/goss goss_format: documentation tasks: - name: Download and install Goss get_url: - url: "{{ goss_url }}" - dest: "{{ goss_dst }}" + url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + dest: "{{ goss_bin }}" sha256sum: "{{ goss_sha256sum }}" mode: 0755 - register: download_goss - until: download_goss is succeeded - retries: 3 + + - name: Create Molecule directory for test files + file: + path: "{{ goss_test_directory }}" + state: directory + + - name: Find Goss tests on localhost + shell: "find {{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }} \\( -name 'test_*.yml' -and -not -name 'test_host_*.yml' \\) -or -name 'test_host_{{ ansible_hostname }}*.yml'" + delegate_to: localhost + register: test_files + + - name: debug + debug: + msg: "{{ test_files.stdout_lines }}" + verbosity: 3 - name: Copy Goss tests to remote copy: src: "{{ item }}" dest: "{{ goss_test_directory }}/{{ item | basename }}" - with_fileglob: - - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml" + with_items: + - "{{ test_files.stdout_lines }}" - name: Register test files shell: "ls {{ goss_test_directory }}/test_*.yml" register: test_files - name: Execute Goss tests - command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}" + command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}" register: test_results with_items: "{{ test_files.stdout_lines }}" + ignore_errors: true - name: Display details about the Goss results debug: diff --git a/test/scenarios/verifier/molecule/goss/verify.yml b/test/scenarios/verifier/molecule/goss/verify.yml index e98b7ffe70..61baa5eb07 100644 --- a/test/scenarios/verifier/molecule/goss/verify.yml +++ b/test/scenarios/verifier/molecule/goss/verify.yml @@ -1,4 +1,9 @@ --- +# This is an example playbook to execute goss tests. +# Tests need distributed to the appropriate ansible host/groups +# prior to execution by `goss validate`. + +{% raw -%} - name: Verify hosts: all become: true @@ -22,12 +27,22 @@ path: "{{ goss_test_directory }}" state: directory + - name: Find Goss tests on localhost + shell: "find {{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }} \\( -name 'test_*.yml' -and -not -name 'test_host_*.yml' \\) -or -name 'test_host_{{ ansible_hostname }}*.yml'" + delegate_to: localhost + register: test_files + + - name: debug + debug: + msg: "{{ test_files.stdout_lines }}" + verbosity: 3 + - name: Copy Goss tests to remote copy: src: "{{ item }}" dest: "{{ goss_test_directory }}/{{ item | basename }}" - with_fileglob: - - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml" + with_items: + - "{{ test_files.stdout_lines }}" - name: Register test files shell: "ls {{ goss_test_directory }}/test_*.yml" @@ -49,3 +64,4 @@ msg: "Goss failed to validate" when: item.rc != 0 with_items: "{{ test_results.results }}" +{% endraw -%}