Skip to main content

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:

ExampleOn the host
Deploy a filewrites /etc/osapi/file-example.conf: listen 8080
Render a templatewrites /etc/osapi/file-example.conf: host test-host port 8080

The command fails in these cases:

CallFlagsFails with
A relative path--object-name example.conf --path etc/xstartswith
No object--path /etc/osapi/file-example.confrequired
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.confmax
A group that is an option--object-name example.conf --path /etc/osapi/file-example.conf --group -raccount_name
An owner that is an option--object-name example.conf --path /etc/osapi/file-example.conf --owner -raccount_name
A content type that is neither--object-name example.conf --path /etc/osapi/file-example.conf --content-type zipenum

Permission​

It needs the file:write permission. osapi controller role get --name <role> shows what a role grants.

Flags​

FlagDescriptionDefault
--content-typeHow the object is written: raw as it is, or template rendered with .Facts, .Vars and .Hostname; the object's own when empty (raw, template)
--groupGroup that owns the file; left as written when empty
--modePermissions in octal, such as 0644; when empty, a file keeps its mode and a new file gets 0644
--object-nameThe object of the object store, from osapi client file list (required)
--ownerUser that owns the file; left as written when empty
--pathAbsolute path of the file on the host (required)
-T, --targetTarget: _all, _any, hostname, or label (group:web.dev)_all
--varsVariables of a template, as .Vars, each as key=value

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml
--urlBase URL the CLI client connects to (controller.client.url)https://localhost:8080

Output tells how the result is printed, and what --json gives.