|
| 1 | +--- |
| 2 | +# This is an example playbook to execute goss tests. |
| 3 | +# Tests need distributed to the appropriate ansible host/groups |
| 4 | +# prior to execution by `goss validate`. |
| 5 | +# |
| 6 | +# The goss ansible module is installed with molecule. The ANSIBLE_LIBRARY |
| 7 | +# path is updated appropriately on `molecule verify`. |
| 8 | + |
| 9 | +# Details about ansible module: |
| 10 | +# - https://github.com/indusbox/goss-ansible |
| 11 | + |
| 12 | +- name: Verify |
| 13 | + hosts: all |
| 14 | + vars: |
| 15 | + goss_version: v0.3.11 |
| 16 | + goss_sha256sum: 7a751c102abac61fd8dff45f87f36c3732cb5158e1414ab78e6877864fc2f7a4 |
| 17 | + goss_arch: amd64 |
| 18 | + goss_dst: /usr/local/bin/goss |
| 19 | + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" |
| 20 | + goss_test_directory: /tmp |
| 21 | + goss_format: documentation |
| 22 | + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" |
| 23 | + molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" |
| 24 | + |
| 25 | + tasks: |
| 26 | + - name: Download and install goss |
| 27 | + get_url: |
| 28 | + url: "{{ goss_url }}" |
| 29 | + dest: "{{ goss_dst }}" |
| 30 | + mode: 0755 |
| 31 | + |
| 32 | + - name: Copy tests to remote |
| 33 | + template: |
| 34 | + src: "{{ item }}" |
| 35 | + dest: "{{ goss_test_directory }}/{{ item | basename }}" |
| 36 | + with_fileglob: |
| 37 | + - "{{ playbook_dir }}/tests/test_*.yml" |
| 38 | + |
| 39 | + - name: Register test files |
| 40 | + shell: "ls {{ goss_test_directory }}/test_*.yml" |
| 41 | + register: test_files |
| 42 | + |
| 43 | + - name: Execute Goss tests |
| 44 | + command: "goss -g {{ item }} validate --format {{ goss_format }}" |
| 45 | + register: test_results |
| 46 | + with_items: "{{ test_files.stdout_lines }}" |
| 47 | + ignore_errors: true |
| 48 | + |
| 49 | + - name: Display details about the goss results |
| 50 | + debug: |
| 51 | + msg: "{{ item.stdout_lines }}" |
| 52 | + with_items: "{{ test_results.results }}" |
| 53 | + |
| 54 | + - name: Fail when tests fail |
| 55 | + fail: |
| 56 | + msg: "Goss failed to validate" |
| 57 | + when: item.rc != 0 |
| 58 | + with_items: "{{ test_results.results }}" |
0 commit comments