Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-var-file argument has no effect #9588

Closed
cpcloud opened this issue Dec 9, 2020 · 4 comments · Fixed by #9592
Closed

-var-file argument has no effect #9588

cpcloud opened this issue Dec 9, 2020 · 4 comments · Fixed by #9592
Assignees
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. type/bug

Comments

@cpcloud
Copy link

cpcloud commented Dec 9, 2020

Nomad version

Output from nomad version

❯ nomad version
Nomad v1.0.0

Operating system and Environment details

OS: NixOS

Issue

The -var-file argument appears to have no effect when running jobs.

After digging around in the code, it looks like the code called by nomad job run here

job, err := c.JobGetter.ApiJobWithArgs(args[0], varArgs, varFiles)
passes varFiles in here
func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []string) (*api.Job, error) {
, but the varfiles variable is never used in the body of ApiJobWithArgs so the variables never get interpolated in.

Reproduction steps

Make a file with a command variable defined, this can be any string but I set it to a valid executable path.

❯ cat test.vars
command = "/run/current-system/sw/bin/ls"

Run the job file below:

❯ nomad job run -var-file="./test.vars" ./test.nomad
Error getting job struct: Error parsing job file from ./test.nomad:
<nil>: Unset variable "command"; A used variable must be set or have a default value; see https://packer.io/docs/configuration/from-1.5/syntax for details.

Job file (if appropriate)

variable "command" {
  type = string
}

job "test" {
  group "test" {
    task "test" {
      driver = "raw_exec"
      config {
        command = "${var.command}"
      }
    }
  }
}
@notnoop notnoop self-assigned this Dec 9, 2020
@notnoop notnoop added stage/accepted Confirmed, and intend to work on. No timeline committment though. type/bug labels Dec 9, 2020
@cpcloud
Copy link
Author

cpcloud commented Dec 9, 2020

Looks like it just needs to be passed in, according to this test

VarFiles: []string{varFile.Name()},

@notnoop
Copy link
Contributor

notnoop commented Dec 9, 2020

Thanks for reporting the bug! That's embarrassing 🤦 . We'll follow up with a fix soon.

notnoop pushed a commit that referenced this issue Dec 9, 2020
Apparently, we missed passing VarFile argument, so var files were
ignored.

Fixes #9588
@notnoop
Copy link
Contributor

notnoop commented Dec 9, 2020

Thanks @cpcloud again. I have merged the fix, and it should be out in 1.0.1!

schmichael pushed a commit that referenced this issue Dec 16, 2020
Apparently, we missed passing VarFile argument, so var files were
ignored.

Fixes #9588
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants