github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/commands/var/put.mdx (about) 1 --- 2 layout: docs 3 page_title: "Command: var put" 4 description: |- 5 The "var put" command writes a variable to the given path in Nomad. 6 --- 7 8 # Command: var put 9 10 The `var put` command creates or updates an existing [variable][]. 11 12 ## Usage 13 14 ```plaintext 15 nomad var put [options] <variable spec file reference> [<key>=<value>]... 16 nomad var put [options] <path to store variable> [<variable spec file reference>] [<key>=<value>]... 17 ``` 18 19 Variable metadata and items can be supplied using a variable specification, by 20 using command arguments, or by a combination of the two techniques. An entire 21 variable specification can be provided to the command via standard input (stdin) 22 by setting the first argument to "-" or from a file by using an @-prefixed path 23 to a variable specification file. When providing variable data via stdin, you 24 must provide the `-in` flag with the format of the specification, which must be 25 either "hcl" or "json". 26 27 Items to be stored in the variable can be supplied using the specification, as a 28 series of key-value pairs, or both. The value for a key-value pair can be a 29 string, an @-prefixed file reference, or a '-' to get the value from stdin. Item 30 values provided from file references or stdin are consumed as-is with no 31 additional processing and do not require the input format to be specified. 32 33 Values supplied as command line arguments supersede values provided in any 34 variable specification piped into the command or loaded from file. If ACLs are 35 enabled, this command requires the `variables:write` capability for the 36 destination namespace and path. See the [ACL policy][] documentation for 37 details. 38 39 ## Restrictions 40 41 Variable paths are restricted to [RFC3986][] URL-safe characters that don't 42 conflict with the use of the characters `@` and `.` in template blocks. This 43 includes alphanumeric characters and the special characters `-`, `_`, `~`, and 44 `/`. Paths may be up to 128 bytes long. The following regex matches the allowed 45 paths: `^[a-zA-Z0-9-_~/]{1,128}$` 46 47 Variable items are restricted to 16KiB in size. This limit is calculated by 48 taking the sum of the length in bytes of all of the unencrypted keys and values. 49 50 ## General Options 51 52 @include 'general_options.mdx' 53 54 ## Put Options 55 56 - `-check-index` `(int: <unset>)`: If set, the variable is only acted upon if 57 the server-side version's index matches the provided value. When a variable 58 specification contains a modify index, that modify index is used as the 59 check-index for the check-and-set operation and can be overridden using this 60 flag. 61 62 - `-force`: Perform this operation regardless of the state or index of the 63 variable on the server-side. 64 65 - `-in` `(enum: hcl | json)`: Parser to use for data supplied via standard input 66 or when the variable specification's type can not be known using the file 67 extension. Defaults to "json". 68 69 - `-out` `(enum: go-template | hcl | json | none | table)`: Format to render 70 created or updated variable. Defaults to "none" when stdout is a terminal and 71 "json" when the output is redirected. 72 73 - `-template` `(string: "")`: Template to render output with. Required when 74 format is "go-template", invalid for other formats. 75 76 - `-verbose`: Provides additional information via standard error to preserve 77 standard output (stdout) for redirected output. 78 79 ## Examples 80 81 Writes the data to the path "secret/creds": 82 83 ```shell-session 84 $ nomad var put secret/creds passcode=my-long-passcode 85 ``` 86 87 The data can also be consumed from a file on disk by prefixing with the "@" 88 symbol. For example, you can store a variable using a specification created with 89 the `nomad var init` command. 90 91 ```shell-session 92 $ nomad var put secret/foo @spec.nv.json 93 ``` 94 95 Or it can be read from standard input using the "-" symbol: 96 97 ```shell-session 98 $ echo "abcd1234" | nomad var put secret/foo bar=- 99 ``` 100 101 102 [variable]: /docs/concepts/variables 103 [ACL Policy]: /docs/other-specifications/acl-policy#variables 104 [RFC3986]: https://www.rfc-editor.org/rfc/rfc3986#section-2