Update
Deploy an object of the object store to a path.
Writes the object at the path with its mode and ownership, and keeps a record of it. A template object, or content_type template, is rendered first with .Facts, .Vars and .Hostname. The record keeps the SHA-256 of the object as it was read. A file that holds the content, mode and owner already, from the same object, does not change and reports changed: false. osapi client file stale list compares the object now with that SHA-256, so it shows the deployments whose object changed since.
osapi client node file update [flags]
Examples
# Deploy a file
osapi client node file update --target web-01 --object-name example.conf --path /etc/osapi/file-example.conf
# Render a template
osapi client node file update --target web-01 --object-name example.conf.tmpl --path /etc/osapi/file-example.conf --vars port=8080
# A file that holds the object
osapi client node file update --target web-01 --object-name example.conf --path /etc/osapi/file-example.conf
Result
Deploy a file, on one host:
$ osapi client node file update --target web-01 --object-name example.conf --path /etc/osapi/file-example.conf Results: HOSTNAME STATUS PATH SHA256 web-01 changed /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 1 host: 1 changed job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9
On each host, where one cannot run it:
$ osapi client node file update --target _all --object-name example.conf --path /etc/osapi/file-example.conf Results: HOSTNAME STATUS PATH SHA256 web-01 changed /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 web-02 changed /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 3 hosts: 2 changed, 1 skipped job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9 Details: mac-01 skipped operation not supported on this OS family
With --json, the API's response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"path": "/etc/osapi/file-example.conf",
"sha256": "0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60",
"status": "ok"
}
]
}
Render a template, on one host:
$ osapi client node file update --target web-01 --object-name example.conf.tmpl --path /etc/osapi/file-example.conf --vars port=8080 Results: HOSTNAME STATUS PATH SHA256 web-01 changed /etc/osapi/file-example.conf 28ef41e1ff26302a25da25eaa7b2762f2d55d0fdc0631a4f6a8c380d2b8640d4 1 host: 1 changed job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9
On each host, where one cannot run it:
$ osapi client node file update --target _all --object-name example.conf.tmpl --path /etc/osapi/file-example.conf --vars port=8080 Results: HOSTNAME STATUS PATH SHA256 web-01 changed /etc/osapi/file-example.conf 28ef41e1ff26302a25da25eaa7b2762f2d55d0fdc0631a4f6a8c380d2b8640d4 web-02 changed /etc/osapi/file-example.conf 28ef41e1ff26302a25da25eaa7b2762f2d55d0fdc0631a4f6a8c380d2b8640d4 3 hosts: 2 changed, 1 skipped job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9 Details: mac-01 skipped operation not supported on this OS family
With --json, the API's response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"path": "/etc/osapi/file-example.conf",
"sha256": "28ef41e1ff26302a25da25eaa7b2762f2d55d0fdc0631a4f6a8c380d2b8640d4",
"status": "ok"
}
]
}
A file that holds the object, on one host:
$ osapi client node file update --target web-01 --object-name example.conf --path /etc/osapi/file-example.conf Results: HOSTNAME STATUS PATH SHA256 web-01 ok /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 1 host: 1 ok job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9
On each host, where one cannot run it:
$ osapi client node file update --target _all --object-name example.conf --path /etc/osapi/file-example.conf Results: HOSTNAME STATUS PATH SHA256 web-01 ok /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 web-02 ok /etc/osapi/file-example.conf 0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60 3 hosts: 2 ok, 1 skipped job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9 Details: mac-01 skipped operation not supported on this OS family
With --json, the API's response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": false,
"hostname": "web-01",
"path": "/etc/osapi/file-example.conf",
"sha256": "0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60",
"status": "ok"
}
]
}
With the default settings, each example does this on the host:
| Example | On the host |
|---|---|
| Deploy a file | writes /etc/osapi/file-example.conf: listen 8080 |
| Render a template | writes /etc/osapi/file-example.conf: host test-host port 8080 |
The command fails in these cases:
| Call | Flags | Fails with |
|---|---|---|
| A relative path | --object-name example.conf --path etc/x | startswith |
| No object | --path /etc/osapi/file-example.conf | required |
| A mode that is not octal | --object-name example.conf --path /etc/osapi/file-example.conf --mode rw-r--r-- | file_mode |
| An object name longer than 255 characters | --object-name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --path /etc/osapi/file-example.conf | max |
| A group that is an option | --object-name example.conf --path /etc/osapi/file-example.conf --group -r | account_name |
| An owner that is an option | --object-name example.conf --path /etc/osapi/file-example.conf --owner -r | account_name |
| A content type that is neither | --object-name example.conf --path /etc/osapi/file-example.conf --content-type zip | enum |
Permission
It needs the file:write permission. osapi controller role get --name <role>
shows what a role grants.
Flags
| Flag | Description | Default |
|---|---|---|
--content-type | How the object is written: raw as it is, or template rendered with .Facts, .Vars and .Hostname; the object's own when empty (raw, template) | |
--group | Group that owns the file; left as written when empty | |
--mode | Permissions in octal, such as 0644; when empty, a file keeps its mode and a new file gets 0644 | |
--object-name | The object of the object store, from osapi client file list (required) | |
--owner | User that owns the file; left as written when empty | |
--path | Absolute path of the file on the host (required) | |
-T, --target | Target: _all, _any, hostname, or label (group:web.dev) | _all |
--vars | Variables of a template, as .Vars, each as key=value |
Global flags
| Flag | Description | Default |
|---|---|---|
-d, --debug | Enable or disable debug mode | |
-j, --json | Enable JSON output | |
-f, --osapi-file | Path to config file; without one at the default path, osapi runs on the defaults | /etc/osapi/osapi.yaml |
--url | Base URL the CLI client connects to (controller.client.url) | https://localhost:8080 |
Output tells how the result is printed, and what --json
gives.