Questions about Nomad-pack

Hello,
I am having some difficulties getting started with nomad-pack and I’m wondering if someone can give me some pointers.

nomad-pack “Nomad Pack v0.0.1-techpreview3 (2acec48)”

Running on an M1 Apple mac remotely.
I have exported NOMAD_ADDR=“http://1.2.3.4:4646/

  1. How do you pass the datacenter to the nomad-pack command? Info says a “(list of string)” but I haven’t been able to figure out what that looks like. I’ve been able to add it to a file, but I need to be able to pass it on the command line.
datacenters = [
  "dev"
]
  1. After I added “datacenters” to the file, and called nomad-pack with -f ./file I’m now getting a different error.
! Failed Job Conflict Validation

	Error:   No path to region
	Type:    *v1.APIError
	Context:
	         - Template Name: hello_world/templates/hello_world.nomad.tpl

I don’t have anything special that I know of set for “region” and it seems the template would set it to “global”.

Any pointers or help would be greatly appreciated.

TIA

Hi @plesher,

  1. You can specify a list of strings on the CLI using -var='datacenters=["dev"]' syntax.

  2. Could you provide a little more debugging data to help such as what the template looks like you are using as well as the output using the Nomad CLI when running nomad server members?

Thanks,
jrasell and the Nomad team

Hi @jrasell ,
Thanks for the tip on setting the datacenters! That seems to work.

I switched off the laptop and am trying to run directly on one of the nomad servers.
Running nomad server members :

# nomad server members
Name                                   Address       Port  Status  Leader  Protocol  Build  Datacenter  Region
ip-172-X-X-Y.dev.test.dom.us-east-1  172.X.X.Y  4648  alive   true    2         1.2.6  dev         us-east-1
ip-172-X-X-Z.dev.test.dom.us-east-1  172.X.X.Z  4648  alive   false   2         1.2.6  dev         us-east-1

I am using a brand new install of nomad-pack and new run of nomad-pack registry list and just the simple hello_world pack straight from the registry.

# nomad-pack registry list
          PACK NAME          |  REF   | METADATA VERSION | REGISTRY |     REGISTRY URL
-----------------------------+--------+------------------+----------+-----------------------
  alertmanager               | latest | 0.0.1            | default  | github.com/hashicorp
  aws_efs_csi                | latest | 0.0.1            | default  | github.com/hashicorp
  boundary                   | latest | 0.0.1            | default  | github.com/hashicorp
  chaotic_ngine              | latest | 0.0.1            | default  | github.com/hashicorp
  csi_openstack_cinder       | latest | 0.0.1            | default  | github.com/hashicorp
  drone                      | latest | 0.0.1            | default  | github.com/hashicorp
  faasd                      | latest | 0.0.1            | default  | github.com/hashicorp
  fabio                      | latest | 0.0.1            | default  | github.com/hashicorp
  grafana                    | latest | 0.1.0            | default  | github.com/hashicorp
  haproxy                    | latest | 0.0.1            | default  | github.com/hashicorp
  hashicups                  | latest | 0.0.1            | default  | github.com/hashicorp
  hello_world                | latest | 0.0.1            | default  | github.com/hashicorp
  influxdb                   | latest | 0.0.1            | default  | github.com/hashicorp
  jaeger                     | latest | 0.0.1            | default  | github.com/hashicorp
  jenkins                    | latest | 0.0.1            | default  | github.com/hashicorp
  kibana                     | latest | 0.0.1            | default  | github.com/hashicorp
  loki                       | latest | 0.0.1            | default  | github.com/hashicorp
  nextcloud                  | latest | 0.0.1            | default  | github.com/hashicorp
  nginx                      | latest | 0.0.1            | default  | github.com/hashicorp
  nomad_autoscaler           | latest | 0.0.1            | default  | github.com/hashicorp
  nomad_ingress_nginx        | latest | 0.0.1            | default  | github.com/hashicorp
  opentelemetry_collector    | latest | 0.0.1            | default  | github.com/hashicorp
  outline                    | latest | 0.0.1            | default  | github.com/hashicorp
  prometheus                 | latest | 0.0.1            | default  | github.com/hashicorp
  prometheus_consul_exporter | latest | 0.0.1            | default  | github.com/hashicorp
  prometheus_node_exporter   | latest | 0.0.1            | default  | github.com/hashicorp
  prometheus_snmp_exporter   | latest | 0.0.1            | default  | github.com/hashicorp
  promtail                   | latest | 0.0.1            | default  | github.com/hashicorp
  rabbitmq                   | latest | 0.0.1            | default  | github.com/hashicorp
  redis                      | latest | 0.0.1            | default  | github.com/hashicorp
  simple_service             | latest | 0.0.1            | default  | github.com/hashicorp
  sonarqube                  | latest | 0.0.1            | default  | github.com/hashicorp
  tempo                      | latest | 0.0.1            | default  | github.com/hashicorp
  tfc_agent                  | latest | 0.1.0            | default  | github.com/hashicorp
  traefik                    | latest | 0.1.0            | default  | github.com/hashicorp
  vector                     | latest | 0.0.1            | default  | github.com/hashicorp
  wordpress                  | latest | 0.0.1            | default  | github.com/hashicorp
# nomad-pack plan -var='datacenters=["dev"]' hello_world
! Failed Job Conflict Validation

	Error:   No path to region
	Type:    *v1.APIError
	Context:
	         - Template Name: hello_world/templates/hello_world.nomad.tpl

I found the template in ~/.cache/ directory.

# cat /root/.cache/nomad/packs/default/hello_world@latest/templates/hello_world.nomad.tpl
job [[ template "job_name" . ]] {
  [[ template "region" . ]]
  datacenters = [[ .hello_world.datacenters | toStringList ]]
  type = "service"

  group "app" {
    count = [[ .hello_world.count ]]

    network {
      port "http" {
        to = 8000
      }
    }

    [[ if .hello_world.register_consul_service ]]
    service {
      name = "[[ .hello_world.consul_service_name ]]"
      tags = [[ .hello_world.consul_service_tags | toStringList ]]
      port = "http"

      check {
        name     = "alive"
        type     = "http"
        path     = "/"
        interval = "10s"
        timeout  = "2s"
      }
    }
    [[ end ]]

    restart {
      attempts = 2
      interval = "30m"
      delay = "15s"
      mode = "fail"
    }

    task "server" {
      driver = "docker"

      config {
        image = "mnomitch/hello_world_server"
        ports = ["http"]
      }

      env {
        MESSAGE = [[.hello_world.message | quote]]
      }
    }
  }
}

It doesn’t matter what pack I tried to run from the registry, I get the same error.

# nomad-pack plan loki
! Failed Job Conflict Validation

	Error:   No path to region
	Type:    *v1.APIError
	Context:
	         - Template Name: loki/templates/loki.nomad.tpl

Trying it with verbose

# nomad-pack plan -verbose hello_world
! Failed Job Conflict Validation

	Error:   No path to region
	Type:    *v1.APIError
	Context:
	         - Template Name: hello_world/templates/hello_world.nomad.tpl

And when I try -verbose and datacenters:

# nomad-pack plan -verbose hello_world -var='datacenters=["dev"]'
! Error Parsing Args Or Flags

	Error:   Flags must be specified before positional arguments when using Go standard
 library style flags. For example, "nomad-pack plan -verbose example" instead
 of "nomad-pack plan example -verbose".

 The CLI also accepts posix flags, which does allow flags after positional
 arguments. For example, both "nomad-pack plan --verbose example" and
 "nomad-pack plan example --verbose" are valid commands.
	Type:    *errors.errorString

  See "nomad-pack plan --help"
# nomad-pack plan hello_world -var='datacenters=["dev"]' --verbose
! Error Parsing Args Or Flags

	Error:   Flags must be specified before positional arguments when using Go standard
 library style flags. For example, "nomad-pack plan -verbose example" instead
 of "nomad-pack plan example -verbose".

 The CLI also accepts posix flags, which does allow flags after positional
 arguments. For example, both "nomad-pack plan --verbose example" and
 "nomad-pack plan example --verbose" are valid commands.
	Type:    *errors.errorString

  See "nomad-pack plan --help"

Any help would be appreciated!

Hi @plesher,

Thanks for the additional information.

The nomad server members output shows your cluster is running as region us-east-1 and not global. You will therefore need to pass this parameter to your template so it targets the correct region.

As the error suggests, the positional arguments need to be at the end of the command. In this case your example command should be nomad-pack plan -verbose -var='datacenters=["dev"]' hello_world.

Including the region modification I believe you should try nomad-pack plan -verbose -var='datacenters=["dev"]' -var='region=us-east-1' hello_world as the full command.

Thanks,
jrasell and the Nomad team

Hi @jrasell
Thanks again for the info!

Unfortunately, the command didn’t work and gave the same error:

 ~]# nomad-pack plan -verbose -var='datacenters=["dev"]' -var='region=us-east-1' hello_world
! Failed Job Conflict Validation

	Error:   No path to region
	Type:    *v1.APIError
	Context:
	         - Template Name: hello_world/templates/hello_world.nomad.tpl

But your comments got me thinking about region. If I set the NOMAD_REGION env variable, it started working.

~]# export NOMAD_REGION="us-east-1"
~]# nomad-pack run -var='datacenters=["dev"]' hello_world
  Evaluation ID: 990f43ad-f553-1e06-7c80-16a146a7659d
  Job 'hello_world' in pack deployment 'hello_world@latest' registered successfully
Pack successfully deployed. Use hello_world with --ref=latest to manage this this deployed instance with plan, stop, destroy, or info

Congrats! You deployed a simple service on Nomad.

I’m still not sure why it wouldn’t pick up the region via the -var flag.

Thanks!