Skip to content

Support multiple vars files #1023

Open
@Lirt

Description

@Lirt

Describe the feature:

Allow multiple variable files to be specified on the command line. Currently we can only define one variable file using --vars var-file.yaml.

Motivation for this is scenario when goss is used in combination with ansible. In this scenario user cannot specify --vars files to be for example ./ansible/inventory/prod/group_vars/all.yaml, ./ansible/inventory/prod/group_vars/v1.32.yaml and ./tests/my-extra-goss-vars.yaml.

Advantage of being able to specify this is in repositories that build multiple images with packer (using packer goss provisioner plugin) in which images are provisioned by ansible and then goss tested. In that case the test file has to redefine variables which are already defined in ansible (eg. package versions, which packages are installed, extra packages, etc).

This way there is no need to redefine expected outputs into goss-vars file(s).

Example

Buildling multiple images of kubernetes versions with packer. Packer uses goss plugin. User passes multiple files into goss_vars_files. The pipeline will configure packer variable var.kubernetes_series to be equal to CI var KUBERNETES_SERIES (filled by using matrix feature - matrix of variables to build multiple images, each with different kubernetes series value).

Final goss command example (with packer it will be invoked over the plugin interface):

goss \
  --vars "./ansible/inventory/prod/group_vars/all.yaml" \
  --vars "./ansible/inventory/prod/group_vars/v${KUBERNETES_SERIES}.yaml" \
  --vars "./tests/common-goss-vars.yaml" \
  --vars-inline "{ kubernetes_series: \"${KUBERNETES_SERIES}\" }" \
  validate

Content of file ./ansible/inventory/prod/group_vars/all.yaml:

kubernetes_deb_repo: "https://pkgs.k8s.io/core:/stable:/{{ kubernetes_series }}/deb/"

Content of file ./ansible/inventory/prod/group_vars/v1.32.yaml:

---
kubernetes_cni_deb_version: "1.6.0-1.1"

Then goss file goss.yaml can contain:

package:
  kubelet:
    installed: true
    versions:
    - {{ kubernetes_cni_deb_version }}

Describe the solution you'd like
Support entering --vars multiple times. Override empty keys by subsequently defined file.

Describe alternatives you've considered
I haven't found any. Let me know if you see one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions