-1

I have a molecule scenario that creates 3 docker instances, each having a different configuration from the same role. The three communicates with each other as I put the instances IP addresses in their respective configuration files.

I need to test that the correct IP address is set the config files of each instance.

How can I access ansible group and host variables from goss?

1
0

Since goss can use variables from a yaml or json file, I just modified the verify.yml example playbook to export this variable and use it in the goss command.

- name: Verify
  hosts: all
  become: true
  vars:
    [...]
    goss_vars: "{{ goss_test_directory }}/vars"
  tasks:
    [...]
    - name: Register hostvars
      copy:
        content: "{'hostvars': {{ hostvars }}}"
        dest: "{{ goss_vars }}"

    - name: Execute Goss tests
      command: "{{ goss_bin }} --vars {{ goss_vars }} -g {{ item }} validate --format {{ goss_format }}"
      register: test_results
      with_items: "{{ test_files.stdout_lines }}"
      failed_when: false

    [...]

Then the variable is available in goss test files as {{ .Vars.hostvars }}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.