### Start http-echo server with arguments Source: https://developer.hashicorp.com/nomad/docs/job-declare/configure-tasks This example shows how to start the http-echo server with static command-line arguments outside of Nomad. ```shell $ http-echo -listen=":5678" -text="hello world" ``` -------------------------------- ### Example Output of Gossip Keyring List Source: https://developer.hashicorp.com/nomad/docs/commands/operator/gossip/keyring-list This example shows the typical output when listing installed encryption keys. The command consolidates keys from all Nomad servers, displaying each key on a new line. ```bash $ nomad operator gossip keyring list Gathering installed encryption keys... Key HD5Y61iE+neTxd1n6TnXhCPViPIUq5QpWq8WW8012XA= AOUfjGff+MrTBzNU7NCOTmYajKRkGv8r2ToxheWd+jk= ``` -------------------------------- ### Generate a Default Example Job File Source: https://developer.hashicorp.com/nomad/docs/commands/job/init This example demonstrates how to generate a default example job file named 'example.nomad.hcl' in the current directory. ```bash $ nomad job init Example job file written to example.nomad.hcl ``` ```bash $ nomad job init Example job file written to example.nomad.hcl ``` -------------------------------- ### Example Node Name and Version Output Source: https://developer.hashicorp.com/nomad/docs/manage/format-cli-output An example of the formatted output showing node names and their corresponding versions. ```text nomad-client-2.node.consul: 0.12.0 nomad-client-3.node.consul: 0.12.0 nomad-client-1.node.consul: 0.12.0 ``` -------------------------------- ### Example Current Scheduler Configuration Source: https://developer.hashicorp.com/nomad/docs/job-scheduling/preemption An example JSON output showing the current scheduler configuration, including preemption settings. ```json { "SchedulerConfig": { "SchedulerAlgorithm": "binpack", "PreemptionConfig": { "SystemSchedulerEnabled": true, "BatchSchedulerEnabled": false, "ServiceSchedulerEnabled": false }, "CreateIndex": 5, "ModifyIndex": 5 }, "Index": 5, "LastContact": 0, "KnownLeader": true } ``` ```json { "SchedulerConfig": { "SchedulerAlgorithm": "binpack", "PreemptionConfig": { "SystemSchedulerEnabled": true, "BatchSchedulerEnabled": false, "ServiceSchedulerEnabled": false }, "CreateIndex": 5, "ModifyIndex": 5 }, "Index": 5, "LastContact": 0, "KnownLeader": true } ``` -------------------------------- ### Install MySQL Client on Ubuntu Source: https://developer.hashicorp.com/nomad/docs/stateful-workloads/static-host-volumes Install the MySQL client on Ubuntu systems to connect to the MySQL database. This is a prerequisite for verifying data persistence. ```bash sudo apt install mysql-client ``` -------------------------------- ### Example: Formatted agent.hcl Source: https://developer.hashicorp.com/nomad/docs/commands/fmt This example shows the same agent configuration file after being formatted by `nomad fmt`, demonstrating canonical formatting. ```hcl server { enabled = true bootstrap_expect = 1 } client { enabled = true } ``` -------------------------------- ### Example NodeListStub Object Details Source: https://developer.hashicorp.com/nomad/docs/manage/format-cli-output An example showing detailed fields of a NodeListStub object, including address, ID, datacenter, and version. ```go &api.NodeListStub{Address:"10.0.2.52", ID:"4f60bc83-71a2-7790-b120-4e55d0e6ed34", Datacenter:"dc1", Name:"nomad-client-2.node.consul", NodeClass:"", Version:"0.12.0", Drain:false, SchedulingEligibility:"eligible", Status:"ready", ...} ``` -------------------------------- ### Install Required Packages (Ubuntu/Debian) Source: https://developer.hashicorp.com/nomad/docs/deploy Installs wget, gpg, and coreutils on Ubuntu/Debian systems. These are prerequisites for adding the HashiCorp repository. ```bash $ sudo apt-get update && \ sudo apt-get install wget gpg coreutils ``` -------------------------------- ### go-netaddrs Executable Output Example Source: https://developer.hashicorp.com/nomad/docs/configuration/server_join Example output format for a go-netaddrs executable, providing a space-delimited list of IPv4 addresses. ```text "1.1.1.1 2.2.2.2" ``` ```text "1.1.1.1 2.2.2.2" ``` -------------------------------- ### Start Nomad Server Agent Source: https://developer.hashicorp.com/nomad/docs/deploy/clusters/connect-nodes Run the Nomad agent with the server configuration file to start a Nomad server node. ```bash $ nomad agent -config=/etc/nomad.d/server.hcl ``` -------------------------------- ### Nomad Setup Command Usage Source: https://developer.hashicorp.com/nomad/docs/commands/setup Basic usage of the `nomad setup` command. Use `-h` with a subcommand for detailed help. ```bash nomad setup [options] ``` ```bash nomad setup [options] ``` -------------------------------- ### setproduct Example: Environments and Apps Source: https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/functions/collection/setproduct Demonstrates finding all combinations of environments and applications using setproduct. ```hcl > setproduct(["development", "staging", "production"], ["app1", "app2"]) [ [ "development", "app1", ], [ "development", "app2", ], [ "staging", "app1", ], [ "staging", "app2", ], [ "production", "app1", ], [ "production", "app2", ], ] ``` -------------------------------- ### Get String Length Example Source: https://developer.hashicorp.com/nomad/docs/reference/hcl2/functions/string/strlen Demonstrates how to get the length of a simple string using the strlen function. ```HCL length("hello") ``` -------------------------------- ### Configure a Plugin with Arguments and Configuration Source: https://developer.hashicorp.com/nomad/docs/configuration/plugin This snippet shows how to configure a plugin named 'example-plugin' with command-line arguments and nested configuration values. Use this to pass specific settings to a plugin binary. ```hcl plugin "example-plugin" { args = ["-my-flag"] config { foo = "bar" bam { baz = 1 } } } ``` -------------------------------- ### Initialize an Example Job File Source: https://developer.hashicorp.com/nomad/docs/govern/sentinel/create Use `nomad job init` to create a sample job file for testing purposes. ```bash $ nomad job init Example job file written to example.nomad.hcl ``` -------------------------------- ### Get Nomad Variable Source: https://developer.hashicorp.com/nomad/docs/manage/variables Use the `nomad var get` command to fetch the contents of an existing variable. This example retrieves the variable stored at path `secret/foo`. ```bash $ nomad var get secret/foo Namespace = default Path = secret/foo Create Time = 2025-11-23T11:14:37-04:00 Check Index = 116 Items passcode = my-long-passcode ``` ```bash $ nomad var get secret/foo Namespace = default Path = secret/foo Create Time = 2025-11-23T11:14:37-04:00 Check Index = 116 Items passcode = my-long-passcode ``` -------------------------------- ### Basic Go Template Example Source: https://developer.hashicorp.com/nomad/docs/reference/go-template-syntax This example demonstrates basic Go template syntax, including outputting strings, using trim markers, adding comments, employing pipelines, assigning variables, and using conditionals. ```Go Template This is a simple template It can {{ "output" }} something. It also {{- " demonstrates" }} trim markers. {{/* it has a comment */}} It can {{ "output" }} something. It can demonstrate {{ "output" | print }} using pipelines. It also {{ $A := "assigns variables" }}{{ $A }}. And conditionals: {{ $B := 2 }}{{ if eq $B 1 }}B is 1{{ else }}B is 2{{ end }} ``` -------------------------------- ### Multi-line Comment Example Source: https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/syntax The '/*' and '*/' delimiters mark the start and end of a comment that can span multiple lines. ```hcl /* This is a multi-line comment that spans several lines. */ ``` -------------------------------- ### Docker Container Task Source: https://developer.hashicorp.com/nomad/docs/job-specification/task Defines a task to start a Docker container. This is a basic example using the docker driver. ```hcl task "server" { driver = "docker" config { image = "hashicorp/http-echo" args = ["-text", "hello world"] } resources { cpu = 20 } } ``` ```hcl task "server" { driver = "docker" config { image = "hashicorp/http-echo" args = ["-text", "hello world"] } resources { cpu = 20 } } ``` -------------------------------- ### Redis Snapshot Save Log Output Source: https://developer.hashicorp.com/nomad/docs/job-declare/nomad-actions Example log output from Redis indicating that a background save operation has started and completed successfully. ```text Tue Nov 28 01:31:14 UTC 2023: Current DB Size: 12 28 Nov 01:31:17.800 * 2 changes in 60 seconds. Saving... 28 Nov 01:31:17.800 * Background saving started by pid 36652 28 Nov 01:31:17.810 * DB saved on disk 28 Nov 01:31:17.810 * RDB: 0 MB of memory used by copy-on-write 28 Nov 01:31:17.902 * Background saving terminated with success Tue Nov 28 01:31:17 UTC 2023: Current DB Size: 12 ``` ```text Tue Nov 28 01:31:14 UTC 2023: Current DB Size: 12 28 Nov 01:31:17.800 * 2 changes in 60 seconds. Saving... 28 Nov 01:31:17.800 * Background saving started by pid 36652 28 Nov 01:31:17.810 * DB saved on disk 28 Nov 01:31:17.810 * RDB: 0 MB of memory used by copy-on-write 28 Nov 01:31:17.902 * Background saving terminated with success Tue Nov 28 01:31:17 UTC 2023: Current DB Size: 12 ``` -------------------------------- ### Create a Sentinel Policy File Source: https://developer.hashicorp.com/nomad/docs/govern/sentinel/create Create a Sentinel policy file named 'test.sentinel'. This example policy always fails for demonstration purposes. ```sentinel ## Test policy always fails for demonstration purposes main = rule { false } ``` -------------------------------- ### Get Unicode String Length Example Source: https://developer.hashicorp.com/nomad/docs/reference/hcl2/functions/string/strlen Illustrates that strlen counts grapheme clusters (Unicode characters) rather than bytes or code points. ```HCL length("πŸ‘ΎπŸ•ΉοΈ") ``` -------------------------------- ### Nomad Consul Setup Command Source: https://developer.hashicorp.com/nomad/docs/commands/setup/consul This command initiates an interactive setup process to configure Nomad workloads for Consul ACL authentication using workload identities. It guides the user through connecting to Consul, creating namespaces, and setting up JWT auth methods and binding rules. ```bash $ nomad setup consul ``` -------------------------------- ### Promote all job groups Source: https://developer.hashicorp.com/nomad/docs/commands/job/promote This example demonstrates how to promote all task groups within a job. It shows the job status before and after the promotion, illustrating the change in deployment status. ```bash # Have two task groups waiting for promotion. $ nomad status example ID = example Name = example Submit Date = 07/25/17 18:35:05 UTC Type = service Priority = 50 Datacenters = dc1 Status = running Periodic = false Parameterized = false Summary Task Group Queued Starting Running Failed Complete Lost cache 0 0 3 0 0 0 web 0 0 3 0 0 0 Latest Deployment ID = 9fa81f27 Status = running Description = Deployment is running but requires manual promotion Deployed Task Group Promoted Desired Canaries Placed Healthy Unhealthy web false 2 1 1 0 0 cache false 2 1 1 0 0 Allocations ID Node ID Task Group Version Desired Status Created At 091377e5 a8dcce2d web 1 run running 07/25/17 18:35:05 UTC d2b13584 a8dcce2d cache 1 run running 07/25/17 18:35:05 UTC 4bb185b7 a8dcce2d web 0 run running 07/25/17 18:31:34 UTC 9b6811ee a8dcce2d cache 0 run running 07/25/17 18:31:34 UTC e0a2441b a8dcce2d cache 0 run running 07/25/17 18:31:34 UTC f2409f7d a8dcce2d web 0 run running 07/25/17 18:31:34 UTC # Promote all groups $ nomad job promote example ==> Monitoring evaluation "6c6e64ae" Evaluation triggered by job "example" Evaluation within deployment: "9fa81f27" Allocation "8fa21654" created: node "a8dcce2d", group "web" Allocation "9f6727a6" created: node "a8dcce2d", group "cache" Evaluation status changed: "pending" -> "complete" ==> Evaluation "6c6e64ae" finished with status "complete" # Inspect the status and see both groups have been promoted. $ nomad status example ID = example Name = example Submit Date = 07/25/17 18:35:05 UTC Type = service Priority = 50 Datacenters = dc1 Status = running Periodic = false Parameterized = false Summary Task Group Queued Starting Running Failed Complete Lost cache 0 0 2 0 2 0 web 0 0 2 0 2 0 Latest Deployment ID = 9fa81f27 Status = successful Description = Deployment completed successfully Deployed Task Group Promoted Desired Canaries Placed Healthy Unhealthy web true 2 1 2 2 0 cache true 2 1 2 2 0 Allocations ID Node ID Task Group Version Desired Status Created At 8fa21654 a8dcce2d web 1 run running 07/25/17 18:35:21 UTC 9f6727a6 a8dcce2d cache 1 run running 07/25/17 18:35:21 UTC 091377e5 a8dcce2d web 1 run running 07/25/17 18:35:05 UTC d2b13584 a8dcce2d cache 1 run running 07/25/17 18:35:05 UTC 4bb185b7 a8dcce2d web 0 stop complete 07/25/17 18:31:34 UTC 9b6811ee a8dcce2d cache 0 stop complete 07/25/17 18:31:34 UTC e0a2441b a8dcce2d cache 0 stop complete 07/25/17 18:31:34 UTC f2409f7d a8dcce2d web 0 stop complete 07/25/17 18:31:34 UTC ``` -------------------------------- ### Nomad Audit Log - Error Response Source: https://developer.hashicorp.com/nomad/docs/configuration/audit This example shows a Nomad audit log entry reflecting a permission denied error during a GET request. ```json { "created_at": "2020-03-24T13:18:36.121978648-04:00", "event_type": "audit", "payload": { "id": "21c6f97a-fbfb-1090-1e34-34d1ece57cc2", "stage": "OperationComplete", "type": "audit", "timestamp": "2020-03-24T13:18:36.121428628-04:00", "version": 1, "auth": { "accessor_id": "anonymous", "name": "Anonymous Token", "policies": ["anonymous"], "create_time": "0001-01-01T00:00:00Z" }, "request": { "id": "c696cc9e-962e-18b3-4097-e0a09070f89e", "operation": "GET", "endpoint": "/v1/jobs?prefix=web", "namespace": { "id": "default" }, "request_meta": { "remote_address": "127.0.0.1:33874", "user_agent": "Go-http-client/1.1" }, "node_meta": { "ip": "127.0.0.1:4646" } }, "response": { "status_code": 403, "error": "Permission denied" } } } ``` -------------------------------- ### Run Consul Agent in Dev Mode Source: https://developer.hashicorp.com/nomad/docs/integrations/consul/service-mesh Starts a Consul agent in development mode. This is a quick way to get a Consul agent running for testing purposes. ```bash $ consul agent -dev ``` ```bash $ consul agent -dev ``` -------------------------------- ### List Nomad Variables with Prefix Filter Source: https://developer.hashicorp.com/nomad/docs/manage/variables List variables in a specific namespace that match a given prefix. This example lists variables in the `prod` namespace starting with `project/ex`. ```bash $ nomad var list -namespace prod project/ex Namespace Path Last Updated prod project/example 2025-09-19T11:29:03-04:00 ``` ```bash $ nomad var list -namespace prod project/ex Namespace Path Last Updated prod project/example 2025-09-19T11:29:03-04:00 ``` -------------------------------- ### Nomad Server Exit on Invalid License Source: https://developer.hashicorp.com/nomad/docs/enterprise/license This example shows the command used to start a Nomad agent with a misconfigured license and the resulting error message. The Nomad server exits with an error if the configured license is invalid. ```bash NOMAD_LICENSE=misconfigured nomad agent -dev ==> No configuration files loaded ==> Starting Nomad agent... ==> Error starting agent: server setup failed: failed to initialize enterprise licensing: a file license was configured but the license is invalid: error decoding version: expected integer ``` ```bash NOMAD_LICENSE=misconfigured nomad agent -dev ==> No configuration files loaded ==> Starting Nomad agent... ==> Error starting agent: server setup failed: failed to initialize enterprise licensing: a file license was configured but the license is invalid: error decoding version: expected integer ``` -------------------------------- ### QEMU Task with Artifact and Configuration Source: https://developer.hashicorp.com/nomad/docs/job-declare/task-driver/qemu This example shows a QEMU task that requires an artifact to be downloaded. It specifies the image path, accelerator, and command-line arguments, along with artifact source and checksum. ```hcl task "virtual" { driver = "qemu" config { image_path = "local/linux.img" accelerator = "kvm" args = ["-nodefaults", "-nodefconfig"] } # Specifying an artifact is required with the "qemu" # driver. This is the # mechanism to ship the image to be run. artifact { source = "https://internal.file.server/linux.img" options { checksum = "md5:123445555555555" } } ``` -------------------------------- ### Get Node Pool Info with Go Template Source: https://developer.hashicorp.com/nomad/docs/commands/node-pool/list Retrieves information for a specific node pool ('prod') and formats it using a Go template. This example shows how to display the name, environment metadata, and description for a single pool. ```bash $ nomad node pool info -t "{{.Name}} [{{.Meta.env}}] - {{.Description}}" prod prod [production] - Node pool for production workloads. ``` -------------------------------- ### Create Namespace with Quota and Description Source: https://developer.hashicorp.com/nomad/docs/commands/namespace/apply Example of creating a new namespace with a specified quota and description. ```bash $ nomad namespace apply -description "Prod API servers" -quota prod api-prod Successfully applied namespace "api-prod"! ``` -------------------------------- ### Install Nomad with Homebrew (macOS) Source: https://developer.hashicorp.com/nomad/docs/deploy Installs Nomad using the `hashicorp/tap/nomad` formula from Homebrew. This installs a signed binary. ```bash $ brew install hashicorp/tap/nomad ``` -------------------------------- ### Interactive Nomad Consul Setup Example Source: https://developer.hashicorp.com/nomad/docs/commands/setup/consul Demonstrates an interactive session for configuring Consul for Nomad workload identity authentication, including prompts for Consul cluster connection, namespace creation, JWT auth method configuration, and binding rule creation. Shows the effect of answering 'no' to configuration prompts and the subsequent cleanup using the `-destroy` flag. ```bash $ nomad setup consul This command will walk you through configuring all the components required for Nomad workloads to authenticate themselves against Consul ACL using their respective workload identities. First we need to connect to Consul. [?] Is "127.0.0.1:8500" the correct address of your Consul cluster? [Y/n] Since you're running Consul Enterprise, we will additionally create a namespace "nomad-workloads" and bind the auth methods to that namespace. [?] Create the namespace "nomad-workloads" in your Consul cluster? [Y/n] [βœ”] Created namespace "nomad-workloads". Nomad needs a JWT auth method for Consul services and tasks. The method for services will be called "nomad-workloads". This is the "nomad-workloads" method configuration: { "Name": "nomad-workloads", "Type": "jwt", "DisplayName": "nomad-workloads", "Description": "Login method for Nomad workloads using workload identities", "TokenLocality": "local", "Config": { "BoundAudiences": [ "consul.io" ], "ClaimMappings": { "consul_namespace": "consul_namespace", "nomad_job_id": "nomad_job_id", "nomad_namespace": "nomad_namespace", "nomad_service": "nomad_service", "nomad_task": "nomad_task" }, "JWKSURL": "http://localhost:4646/.well-known/jwks.json", "JWTSupportedAlgs": [ "RS256" ] }, "CreateIndex": 0, "ModifyIndex": 0, "NamespaceRules": [ { "BindNamespace": "${value.consul_namespace}" } ] } [?] Create "nomad-workloads" auth method in your Consul cluster? [Y/n] [βœ”] Created auth method "nomad-workloads". Consul uses binding rules to map claims between Nomad's JWTs to Consul service identities and ACL roles, so we need to create a two binding rules for the auth method we created above: one for services, and one for tasks. This is the binding rule for services: { "ID": "", "Description": "Binding rule for Nomad services authenticated using a workload identity", "AuthMethod": "nomad-workloads", "Selector": "\"nomad_service\" in value", "BindType": "service", "BindName": "${value.nomad_service}", "CreateIndex": 0, "ModifyIndex": 0 } [?] Create this binding rule in your Consul cluster? [Y/n] [βœ”] Created binding rule for auth method "nomad-workloads". This is the binding rule for tasks: { "ID": "", "Description": "Binding rule for Nomad tasks authenticated using a workload identity", "AuthMethod": "nomad-workloads", "Selector": "\"nomad_service\" not in value", "BindType": "role", "BindName": "nomad-${value.nomad_namespace}-tasks", "CreateIndex": 0, "ModifyIndex": 0 } [?] Create this binding rule in your Consul cluster? [Y/n] n By answering "no" to any of these questions, you are risking an incorrect Consul cluster configuration. Nomad workloads with Workload Identity will not be able to authenticate unless you create missing configuration yourself. [?] Remove everything this command creates? [Y/n] The following items will be deleted: * Auth method: nomad-workloads * Binding rules: 4d80108a-6d77-36e1-71b1-d20a9acf8b17 * Namespace: nomad-workloads [?] Remove all the items listed above? [Y/n] [βœ”] Deleted binding rule "4d80108a-6d77-36e1-71b1-d20a9acf8b17". [βœ”] Deleted auth method "nomad-workloads". [βœ”] Deleted namespace "nomad-workloads". Consul cluster has not been configured for authenticating Nomad tasks and services using workload identitiies. Run the command again to finish the configuration process. ``` -------------------------------- ### Docker Task Configuration with Command Source: https://developer.hashicorp.com/nomad/docs/job-declare/task-driver/docker Illustrates how to specify a custom command to run when the Docker container starts. ```HCL config { command = "my-command" } ``` -------------------------------- ### Action with Arguments Example Source: https://developer.hashicorp.com/nomad/docs/job-specification/action This snippet demonstrates an action that uses arguments to list files in '/tmp'. ```hcl job "example" { # ... group "demo" { # ... task "list-files" { # ... action "list-tmp" { command = "/bin/ls" args = ["-l", "/tmp"] } } } } ``` -------------------------------- ### Example Automatic Variable Access Policy Source: https://developer.hashicorp.com/nomad/docs/concepts/variables An example policy showing automatic variable access for a specific task ('redis' in 'cache' group of 'example' job). ```HCL namespace "default" { variables { path "nomad/jobs" { capabilities = ["read", "list"] } path "nomad/jobs/example" { capabilities = ["read", "list"] } path "nomad/jobs/example/cache" { capabilities = ["read", "list"] } path "nomad/jobs/example/cache/redis" { capabilities = ["read", "list"] } } } ``` ```HCL namespace "default" { variables { path "nomad/jobs" { capabilities = ["read", "list"] } path "nomad/jobs/example" { capabilities = ["read", "list"] } path "nomad/jobs/example/cache" { capabilities = ["read", "list"] } path "nomad/jobs/example/cache/redis" { capabilities = ["read", "list"] } } } ``` -------------------------------- ### Initialize a Host Volume Specification Source: https://developer.hashicorp.com/nomad/docs/commands/volume/init Generates an example volume specification file specifically for a host volume type. Use this when you need to configure host-based storage. ```bash nomad volume init -type=host ``` -------------------------------- ### Install Nomad on Amazon Linux Source: https://developer.hashicorp.com/nomad/docs/install Installs Nomad on Amazon Linux systems using the yum package manager. This involves adding the HashiCorp repository and then installing the nomad package. ```bash sudo yum install -y yum-utils shadow-utils sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo sudo yum install nomad ``` ```bash sudo yum install -y yum-utils shadow-utils sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo sudo yum install nomad ``` -------------------------------- ### Restart Job in Batches with Wait Time Source: https://developer.hashicorp.com/nomad/docs/commands/job/restart This example demonstrates restarting a job named 'example' in batches of 2 allocations, with a 10-second wait between each batch. This is useful for controlling the impact of restarts on a running service. ```bash $ nomad job restart -batch-size=2 -batch-wait=10s example ==> 2023-02-28T18:03:43-05:00: Restarting 5 allocations ==> 2023-02-28T18:03:43-05:00: Restarting 1st batch of 2 allocations 2023-02-28T18:03:43-05:00: Restarting running tasks in allocation "653f983e" for group "web" 2023-02-28T18:03:43-05:00: Restarting running tasks in allocation "4d18e545" for group "web" ==> 2023-02-28T18:03:43-05:00: Waiting 10s before restarting the next batch ==> 2023-02-28T18:03:53-05:00: Restarting 2nd batch of 2 allocations 2023-02-28T18:03:53-05:00: Restarting running tasks in allocation "4fd581ee" for group "proxy" 2023-02-28T18:03:53-05:00: Restarting running tasks in allocation "32e143f8" for group "proxy" ==> 2023-02-28T18:03:53-05:00: Waiting 10s before restarting the next batch ==> 2023-02-28T18:04:03-05:00: Restarting 3rd batch of 1 allocations 2023-02-28T18:04:03-05:00: Restarting running tasks in allocation "77d5c4f6" for group "proxy" ==> 2023-02-28T18:04:03-05:00: Finished job restart All allocations restarted successfully! ``` -------------------------------- ### Job with Artifact and Template Configuration Source: https://developer.hashicorp.com/nomad/docs/job-declare/configure-tasks This example job demonstrates downloading a configuration template as an artifact and then using the template stanza to process it into a final configuration file for the task. Use this pattern when your task requires external configuration files. ```hcl job "docs" { datacenters = ["dc1"] group "example" { task "server" { driver = "exec" artifact { source = "http://example.com/config.hcl.tmpl" destination = "local/config.hcl.tmpl" } template { source = "local/config.hcl.tmpl" destination = "local/config.hcl" } config { command = "my-app" args = [ "-config", "local/config.hcl", ] } } } } ``` -------------------------------- ### Install Nomad on Ubuntu/Debian Source: https://developer.hashicorp.com/nomad/docs/install Installs Nomad on Ubuntu or Debian-based systems using the apt package manager. This involves adding the HashiCorp GPG key and repository, then installing the nomad package. ```bash wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install nomad ``` ```bash wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install nomad ``` -------------------------------- ### Start Nomad Windows Service Source: https://developer.hashicorp.com/nomad/docs/deploy/production/windows-service Initiate the Nomad Windows service using the `sc.exe start` command. The output will display the service's status, type, and PID if successfully started. ```powershell sc.exe start "Nomad" SERVICE_NAME: Nomad TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 8008 FLAGS : ``` ```powershell sc.exe start "Nomad" SERVICE_NAME: Nomad TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 8008 FLAGS : ``` -------------------------------- ### Basic Action Example Source: https://developer.hashicorp.com/nomad/docs/job-specification/action This snippet shows a basic action that executes the '/bin/date' command. ```hcl job "example" { # ... group "demo" { # ... task "show-date" { # ... action "current-date" { command = "/bin/date" } } } } ``` -------------------------------- ### Configure a Strategy Plugin Source: https://developer.hashicorp.com/nomad/docs/autoscaling/agent/strategy Example of how to configure a custom strategy plugin named 'example-strategy-plugin'. This includes specifying the driver, arguments, and a configuration map for the plugin. ```hcl strategy "example-strategy-plugin" { driver = "example-strategy-plugin" args = ["-my-flag"] config = { algorithm = "complex" } } ``` -------------------------------- ### Example CNI Configuration Source: https://developer.hashicorp.com/nomad/docs/job-specification/network This is an example of a CNI configuration file that can be used with Nomad. ```json { "cniVersion": "0.3.1", "name": "mynet", "plugins": [ { "type": "ptp", "ipMasq": true, "ipam": { "type": "host-local", "subnet": "172.16.30.0/24", "routes": [ { "dst": "0.0.0.0/0" } ] } }, { "type": "portmap", "capabilities": { "portMappings": true } } ] } ``` -------------------------------- ### Inspect License from File Path (Example Output) Source: https://developer.hashicorp.com/nomad/docs/commands/license/inspect Displays detailed information and validation status for a Nomad Enterprise license file. ```bash $ nomad license inspect /path/to/nomad/license.hclic Source: /path/to/nomad/license.hclic Product: nomad License ID: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Customer ID: bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb Installation ID: * Issue Time: 2021-12-01 17:49:23.021041516 +0000 UTC Start Time: 2021-12-01 00:00:00 +0000 UTC Expiration Time: 2023-12-01 00:00:00 +0000 UTC Termination Time: 2024-01-01 00:00:00 +0000 UTC Build Date: 2000-01-01 00:00:00 +0000 UTC NonProduction: False Flags: { "modules": [ "multicluster-and-efficiency", "governance-policy" ] } Validation Checks: βœ“ All checks passed ``` -------------------------------- ### Port Allocation Example Source: https://developer.hashicorp.com/nomad/docs/job-specification/network Example of how to define a port allocation with a specific label. ```hcl port "foo" {} ``` -------------------------------- ### HCL Meta Block Example Source: https://developer.hashicorp.com/nomad/docs/job-specification/hcl2 Shows how to use the 'meta' block for configuration, demonstrating the assignment of string values to attributes like 'team' and 'organization'. ```HCL meta { team = "..." organization = "..." } ``` -------------------------------- ### Install consul-cni Plugin (Fedora) Source: https://developer.hashicorp.com/nomad/docs/deploy Installs the consul-cni plugin using dnf for Fedora. ```bash $ sudo dnf -y install consul-cni ``` ```bash $ sudo dnf -y install consul-cni ``` -------------------------------- ### Nomad Agent Startup Log Example Source: https://developer.hashicorp.com/nomad/docs/enterprise/license/utilization-reporting This log output confirms that automated reporting is enabled but product usage metrics are disabled via agent configuration. ```log [INFO] nomad.reporting: reporting agent is enabled and configured [DEBUG] nomad.reporting: product usage reporting disabled via agent configuration [INFO] nomad.reporting: product usage reporting is disabled; usage metrics data will not be collected ``` ```log [INFO] nomad.reporting: reporting agent is enabled and configured [DEBUG] nomad.reporting: product usage reporting disabled via agent configuration [INFO] nomad.reporting: product usage reporting is disabled; usage metrics data will not be collected ``` -------------------------------- ### Install CLI Autocomplete Source: https://developer.hashicorp.com/nomad/docs/commands Run this command to install command autocomplete for the Nomad CLI. ```bash $ nomad -autocomplete-install ``` ```bash $ nomad -autocomplete-install ``` -------------------------------- ### Chunklist Example with Chunk Size 1 Source: https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/functions/collection/chunklist Demonstrates splitting a list of strings into chunks of size 1, effectively creating a list of single-element lists. ```HCL chunklist(["a", "b", "c", "d", "e"], 1) [ ["a"], ["b"], ["c"], ["d"], ["e"] ] ``` -------------------------------- ### Install Homebrew Tap (macOS) Source: https://developer.hashicorp.com/nomad/docs/deploy Installs the HashiCorp tap, which is a repository for all HashiCorp Homebrew packages. ```bash $ brew tap hashicorp/tap ``` -------------------------------- ### Paginate Node Pool List Source: https://developer.hashicorp.com/nomad/docs/commands/node-pool/list Demonstrates how to paginate the output of the node pool list command. This example shows fetching the first two pools and provides instructions on how to retrieve subsequent pages. ```bash $ nomad node pool list -per-page 2 Name Description all Node pool with all nodes in the cluster. default Default node pool. Results have been paginated. To get the next page run: nomad node pool list -per-page 2 -page-token dev $ nomad node pool list -per-page 2 -page-token dev Name Description dev Node pool for dev workloads. prod Node pool for production workloads. ``` -------------------------------- ### Install Nomad (Fedora) Source: https://developer.hashicorp.com/nomad/docs/deploy Installs the Nomad package using dnf from the configured HashiCorp repository. ```bash $ sudo dnf -y install nomad ```