|
| 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 | +- name: Verify |
| 7 | + hosts: all |
| 8 | + become: true |
| 9 | + vars: |
| 10 | + goss_version: v0.3.7 |
| 11 | + goss_arch: amd64 |
| 12 | + goss_dst: /usr/local/bin/goss |
| 13 | + # yamllint disable-line rule:line-length |
| 14 | + goss_sha256sum: 357f5c7f2e7949b412bce44349cd32ab19eb3947255a8ac805f884cc2c326059 |
| 15 | + # yamllint disable-line rule:line-length |
| 16 | + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" |
| 17 | + goss_test_directory: /tmp |
| 18 | + goss_format: tap |
| 19 | + tasks: |
| 20 | + - name: Download and install Goss |
| 21 | + get_url: |
| 22 | + url: "{{ goss_url }}" |
| 23 | + dest: "{{ goss_dst }}" |
| 24 | + sha256sum: "{{ goss_sha256sum }}" |
| 25 | + mode: 0755 |
| 26 | + register: download_goss |
| 27 | + until: download_goss is succeeded |
| 28 | + retries: 3 |
| 29 | + |
| 30 | + - name: Copy Goss tests to remote |
| 31 | + copy: |
| 32 | + src: "{{ item }}" |
| 33 | + dest: "{{ goss_test_directory }}/{{ item | basename }}" |
| 34 | + mode: 0644 |
| 35 | + with_fileglob: |
| 36 | + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml" |
| 37 | + |
| 38 | + - name: Register test files |
| 39 | + shell: "ls {{ goss_test_directory }}/test_*.yml" |
| 40 | + changed_when: false |
| 41 | + register: test_files |
| 42 | + |
| 43 | + - name: Execute Goss tests |
| 44 | + environment: |
| 45 | + # yamllint disable-line rule:line-length |
| 46 | + PATH: '/opt/rh/rh-git218/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' |
| 47 | + command: "{{ goss_dst }} -g {{ item }} validate -f {{ goss_format }}" |
| 48 | + changed_when: false |
| 49 | + register: test_results |
| 50 | + with_items: "{{ test_files.stdout_lines }}" |
| 51 | + |
| 52 | + - name: Display details about the Goss results |
| 53 | + debug: |
| 54 | + msg: "{{ item.stdout_lines }}" |
| 55 | + with_items: "{{ test_results.results }}" |
| 56 | + |
| 57 | + - name: Fail when tests fail |
| 58 | + fail: |
| 59 | + msg: "Goss failed to validate" |
| 60 | + when: item.rc != 0 |
| 61 | + with_items: "{{ test_results.results }}" |
0 commit comments