Skip to content

Commit

Permalink
update goss verify.yml to allow to pass host to run on
Browse files Browse the repository at this point in the history
Signed-off-by: Norbert Varzariu <[email protected]>
  • Loading branch information
Norbert Varzariu committed Jan 2, 2019
1 parent d7397ca commit 37eb692
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 18 additions & 2 deletions test/scenarios/verifier/molecule/goss/verify.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -49,3 +64,4 @@
msg: "Goss failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"
{% endraw -%}

0 comments on commit 37eb692

Please sign in to comment.