-
Notifications
You must be signed in to change notification settings - Fork 67
Subcommand | Synopsis |
---|---|
bulkload | Bulkload value to the K/V store |
delete | Delete a given path from the K/V |
keys | List K/V keys |
lock | Acquire a lock on a given path |
read | Read a value from a given path |
unlock | Release a lock on a given path |
watch | Watch for changes to a K/V path |
write | Write a value to a given path |
Bulkload value to the K/V store
Usage: consul-cli kv bulkload [options]
-
--json=<file>
Path to a JSON file to import -
--prefix=<prefix>
When specified, prefix all keys with this path
$ echo '{"foo":"bar"}' > import.json
$ ./consul-cli kv bulkload --json=import.json
$ ./consul-cli kv read "" --recurse=true --format=json | jq from_entries
{
"foo": "bar"
}
$ ./consul-cli kv bulkload --json=import.json --prefix=test
$ ./consul-cli kv read "" --recurse=true --format=json | jq from_entries
{
"foo": "bar",
"test/foo": "bar"
}
Delete a given path from the K/V store
Usage: consul-cli kv delete [options] path
-
--modifyindex=<index>
Perform a Check-and-Set delete on the path. If the index is non zero, the node is only deleted if<index>
matches the node'sModifyIndex
-
--recurse
When specified, all nodes that are prefixed withpath
are deleted
$ ./consul-cli kv delete --recurse test
$ ./consul-cli kv read test/key1
$
List K/V keys
Usage: consul-cli vk keys [options] path
-
--separator=<path_separator>
Only list keys up to a given separator.
$ ./consul-cli kv keys /
vault/core/audit
vault/core/auth
vault/core/keyring
vault/core/lock
vault/core/master
vault/core/mounts
vault/core/seal-config
vault/sys/policy/default
vault/sys/token/salt
$ ./consul-cli kv keys /vault/ --separator=/
vault/core/
vault/sys/
Acquire a lock on the given path
Usage: consul-cli kv lock [options] path
-
--behavior=[release|delete]
Node behavior when the owning session is invalidated. With the default behavior ofrelease
, the lock is released when the session expires. Withdelete
, the node is deleted from the K/V store -
--ttl=<duration>
Time to live for the lock. When the lock expires, the session is invalidated and the lock is either released or the node is deleted according to thebehavior
. A duration of zero indicates that the lock never expires -
--lock-delay=<duration>
The amount of time before another process can acquire the lock after it is released. A duration of zero indicates that the lock can be immediately acquired after release. The default is15s
-
--session=<sessionId>
Use thesessionId
instead of creating a new one.
$ ./consul-cli kv lock --ttl=0 test/locks
ba7c8cda-d197-a062-4e3e-f9a737237aa1
$ ./consul-cli kv read --format=prettyjson test/locks
{
"Key": "test/locks",
"CreateIndex": 386,
"ModifyIndex": 386,
"LockIndex": 1,
"Flags": 0,
"Value": "",
"Session": "ba7c8cda-d197-a062-4e3e-f9a737237aa1"
}
Retrieve the given path from the K/V store
Usage: consul-cli kv read [options] path
-
--fields=<field1,field2,...>
A comma separated list of fields to display when format istext
. The default field list isValue
-
--format=[text|json|prettyjson]
Specify the output format. One oftext
,json
orprettyjson
-
--delimiter=<fs>
String delimiter to separate the fields when the format istext
. The default is space ' ' -
--header
When specified, output a header row when the format istext
. The default isfalse
-
--recurse
Read all of the nodes
$ ./consul-cli kv read test/node/key1
Value1
$ ./consul-cli kv read --format=prettyjson test/node/key2
{
"Key": "test/node/key2",
"CreateIndex": 317,
"ModifyIndex": 317,
"LockIndex": 0,
"Flags": 0,
"Value": "Value2",
"Session": ""
}
$ ./consul-cli kv read --recurse --fields=key,value --header \
--format=text --delimiter=: test/node
#key:value
test/node/deep/key3:Value3
test/node/key1:Value1
test/node/key2:Value2
Release the lock on a given path
Usage: consul-cli kv unlock [options] path
-
--session
(* Required)
The session ID of the lock holder. This is returned from theconsul-cli kv lock
command. -
--no-destroy
When set, the session is not destroyed. By default the session is destroyed when the lock is released
$ ./consul-cli kv unlock --session=ba7c8cda-d197-a062-4e3e-f9a737237aa1 test/locks
Watch a node for changes. This implements the ?index
HTTP option as a separate
consul-cli command. The command line arguments and output is the same as the kv read
command with the addition of the --wait-index
option.
Usage: consul-cli kv watch [options] path
-
--fields=<field1,field2,...>
A comma separated list of fields to display when format istext
. The default field list isValue
-
--format=[text|json|prettyjson]
Specify the output format. One oftext
,json
orprettyjson
-
--delimiter=<fs>
String delimiter to separate the fields when the format istext
. The default is space ' ' -
--header
When specified, output a header row when the format istext
. The default isfalse
-
--recurse
Read all of the nodes -
--wait-index=<modifyIndex>
Use the value of this option as theWaitIndex
. If the node'sModifyIndex
is greater thanmodifyIndex
, the node is returned. The default value of 0 will immediately return the node if it already exists.
$ ./consul-cli kv watch test/node/key1
Value1
Write a value to the given path. The value can be either text or the path to a file via @/path/to/file.
Usage: consul-cli kv write [options] path value
-
--modifyindex=<index>
Perform a Check-and-Set write on the node. The write only occurs if theModifyIndex
of the node matches<index>
-
--flags=<number>
Set theFlags
field of the node to a integer value between 0 and (2^64 - 1)
$ ./consul-cli kv write test/key1 Value1
$ ./consul-cli kv write test/etc/hosts @/etc/hosts