Nomad: -var-file argument has no effect

Created on 9 Dec 2020  ·  3Comments  ·  Source: hashicorp/nomad

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 https://github.com/hashicorp/nomad/blob/8a66f11bb3e8d64408010f31a888a78e02de59d2/command/job_run.go#L197 passes varFiles in here https://github.com/hashicorp/nomad/blob/86882dffc0c7370c2217aea3da7b232f9a8c6e3c/command/helpers.go#L394, 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}"
      }
    }
  }
}
stagaccepted typbug

All 3 comments

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

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

Was this page helpful?
0 / 5 - 0 ratings