|  | 
|  | 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.2 | 
|  | 11 | +    goss_arch: amd64 | 
|  | 12 | +    goss_dst: /usr/local/bin/goss | 
|  | 13 | +    # yamllint disable-line rule:line-length | 
|  | 14 | +    goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec | 
|  | 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: documentation | 
|  | 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 | +      with_fileglob: | 
|  | 35 | +        - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml" | 
|  | 36 | + | 
|  | 37 | +    - name: Register test files | 
|  | 38 | +      shell: "ls {{ goss_test_directory }}/test_*.yml" | 
|  | 39 | +      register: test_files | 
|  | 40 | + | 
|  | 41 | +    - name: Execute Goss tests | 
|  | 42 | +      # yamllint disable-line rule:line-length | 
|  | 43 | +      command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}" | 
|  | 44 | +      register: test_results | 
|  | 45 | +      with_items: "{{ test_files.stdout_lines }}" | 
|  | 46 | + | 
|  | 47 | +    - name: Display details about the Goss results | 
|  | 48 | +      debug: | 
|  | 49 | +        msg: "{{ item.stdout_lines }}" | 
|  | 50 | +      with_items: "{{ test_results.results }}" | 
|  | 51 | + | 
|  | 52 | +    - name: Fail when tests fail | 
|  | 53 | +      fail: | 
|  | 54 | +        msg: "Goss failed to validate" | 
|  | 55 | +      when: item.rc != 0 | 
|  | 56 | +      with_items: "{{ test_results.results }}" | 
0 commit comments