Repository: goss-org/goss

Issue #784: Add a dynamic dependancy in order for a test to run
Created: 2022-09-14T10:04:19Z
Describe the feature:
Due to the nature and design of many estates some features only exist on certain servers. To make this more dynamic and extendable as well as portable and reuseable. that allows and enables the same config to be run across entire estates rather than individual files per possible server setup.
Problem:
We only need to confirm some server spec if a certain value is true
e.g.
1/ if auditd is installed
2/ then run the following tests.
It could be seen as setting a variable on the fly and ensure the variable value as part of the test. This would also mean certain test would need to run in order. Although as per #742 the subsequent tests may reuse the variable multiple times (example tries to show this too).
This feels more like a programming feature but could extend it usage.
Describe the solution you'd like
A possible way,
add a new option of discovery which runs prior to any other tests to capture and set dynamic variables used by the server spec tests.
These could even be in a dedicated file ensuring that the run before all others.
An example could be (this is very ansible like i am aware)
Example 1
file name: discovery.yml
discovery:
  package:
    auditd:
      installed: true
      register: auditd_installed
sometest1.yml
{{ if .Discovered.auditd_installed }}
file:
  /etc/auditd/audit.conf:
    exists: true
    contains: 
     - 'some string = 1'
    meta:
      test: 1
 {{ end }}
sometest2.yml
{{ if .Discovered.auditd_installed }}
file:
  /etc/auditd/audit.conf:
    exists: true
    contains: 
     - 'enable = true'
     meta:
      test: 2
 {{ end }}
Aware this only gives a boolean value rather than a discovered output. It would be nice if you could capture the other outputs and assign a value. e.g.
Example 2
file name: discovery.yml
discovery:
  package:
    auditd:
      installed: true
      register: auditd_installed
      version: 1.1
sometest1.yml
{{ if .Discovered.auditd_installed.version < "1.1" }}
file:
  /etc/auditd/audit.conf:
    exists: true
    contains: 
     - 'some string = 1'
    meta:
      test: 1
 {{ end }}
sometest2.yml
{{ if eq .Discovered.auditd_installed.version >= "1.1" }}
file:
  /etc/auditd/audit.conf:
    exists: true
    contains: 
     - 'enable = true'
     meta:
      test: 2
 {{ end }}
Describe alternatives you've considered
This could met by using the command test module, but then that is just running a shell script. It doesn't add the efficiency and consistency in the modules already developed.
Thanks again for this project.

Duplicate issue #866: Dinamic variables and envs
Created: 2024-01-17T16:31:04Z
Hello, can I use dinamic variables and envs like this?
command:
  kubectl get nodes:
    exit-status: 0
    stdout:
      not:
        match-regexp: 'NotReady'
  export test="a":
    exit-status: 0



http:
  '{{.Env.test}}':
    status: 200
    timeout: 5000

Closing comment (2024-01-21T18:59:50Z): Using a command output as a variable isn't supported currently. You would have to generate the vars.yaml file prior to running Goss.
This isn't a bad feature request, it's somewhat related to #784
If the vars.yaml supported a simple interface that ran a command to set the car to its stdout.. would that sufficiently solve #784 or does it add too much complexity?