OPSI-CLI User Guide
Usage
opsi-cli is a Python-based binary that operates based on parameters and commands. Every command within opsi-cli can consist of one or several subcommands. The upcoming sections will first introduce the basic functionalities and then delve into the available commands.
Each command in opsi-cli comes with its own help, accessible via the --help parameter. For example, you can use opsi-cli --help or opsi-cli config --help to view detailed information about specific commands.
|
The typical structure for executing an opsi-cli command is as follows:
opsi-cli [OPTIONS] COMMAND [ARGS]...
Options specified immediately after the opsi-cli command are part of the global configuration and therefore apply to all subsequent subcommands. There are three main categories of global options in opsi-cli.
General Options
The parameters in the General options section let you adjust aspects like logging, enable colored output, and configure other settings in opsi-cli.
Output Format
The options found under IO options are used to standardize the output across all subcommands, allowing you to specify output formats and apply filters.
The following example demonstrates how to use these options for filtering and formatting output. In the first command, opsi-cli executes the JSON-RPC method host_getObjects (execute) to display information about OPSI clients from the domain domain.local with names beginning with client:
opsi-cli jsonrpc execute host_getObjects [] '{"id":"client*.domain.local"}'
[
{
"description": "",
"notes": "Created by opsi-deploy-client-agent at Mon, 26 Sep 2022 17:19:29",
"id": "client-linux.domain.local",
"hardwareAddress": "08:00:27:f5:1d:8e",
"ipAddress": "192.168.56.11",
"inventoryNumber": "",
"systemUUID": null,
"opsiHostKey": null,
"created": "2022-09-26 17:19:29",
"lastSeen": "2023-03-08 12:13:10",
"oneTimePassword": null,
"type": "OpsiClient",
"ident": "client-linux.domain.local"
},
[…]
]
The next command formats the output as a table in the terminal and filters it to include only three attributes: id, type, and lastSeen:
opsi-cli --output-format table --attributes id,type,lastSeen jsonrpc execute host_getObjects [] '{"id":"client*.domain.local"}'
If you prefer the CSV format, simply write csv after --output-format instead of table:
opsi-cli --output-format csv --attributes id,type,lastSeen jsonrpc execute host_getObjects [] '{"id":"client*.domain.local"}'
[…]
id;lastSeen;type
client-linux.domain.local;2023-03-08 12:13:10;OpsiClient
client-macos.domain.local;2023-03-15 14:55:37;OpsiClient
client-win10.domain.local;2023-03-15 15:13:46;OpsiClient
You can use the --output-file option to directly write the output to a file.
Service Options
When using opsi-cli outside of the OPSI server, it’s necessary to provide access credentials for the OPSI web service. The relevant parameters for this are --service, --username, and --password:
As an alternative, you can save the access credentials directly on the client. This approach is particularly useful if you need to access multiple OPSI servers, as it allows you to create and manage different service configurations as profiles. To set this up, use the opsi-cli config command. For detailed instructions and options, you can view the online help by entering opsi-cli config service add --help.
|
Commands and Examples
The following sections will detail the currently available commands in opsi-cli and provide examples to illustrate their usage.
config
Use this command to adjust the opsi-cli configuration (see opsi-cli config --help).
Use the following command to view the current configuration and the default settings:
opsi-cli config list
To permanently modify a configuration value, use the command opsi-cli config set <name> <value>. This adjustment will then be applied to all future uses of opsi-cli. If you need to remove a previously set value, use the command opsi-cli config unset <name>. For managing service access configurations, opsi-cli config service provides several subcommands, including add, list, and remove.
jsonrpc
The jsonrpc command in opsi-cli provides access to JSON-RPC methods, allowing their execution on the OPSI server. This functionality enables opsi-cli to fully replace the opsi-admin tool. The jsonrpc command includes two subcommands:
-
opsi-cli jsonrpc methods: This command prints a list of all available API methods along with their parameters. -
opsi-cli jsonrpc execute <method>: Use this command to execute a specified method.
The output of opsi-cli jsonrpc methods also indicates if a method is marked as obsolete in the deprecated column, while the alternative_method column shows the recommended alternative method.
To execute a specific method, append its name after the opsi-cli jsonrpc execute command, for example:
opsi-cli jsonrpc execute authenticated
The syntax for using opsi-cli is similar to that of opsi-admin, as can be seen in a direct comparison:
opsi-admin method authenticated
The way in which method parameters are specified in opsi-cli is exactly the same as in opsi-admin, as illustrated by the following, slightly more complex example:
opsi-cli jsonrpc execute host_getObjects '["created","lastSeen"]' '{"id":"testclient01.uib.local"}'
Old variant:
opsi-admin method host_getObjects '["created","lastSeen"]' '{"id":"testclient01.uib.local"}'
In the two examples provided, the depecated -d parameter for opsi-admin (which used to bypass opsiconfd) is intentionally omitted. Bypassing the OPSI web service in the past, has occasionally led to issues within the OPSI system. Therefore, access to the API is recommended solely via the OPSI web service. It’s important to note that opsi-cli does not support bypassing opsiconfd.
|
When operating directly on the OPSI server, there’s no need to input any access credentials, as opsi-cli automatically retrieves this information from the server configuration. However, if you plan to use opsi-cli in scripts, cronjobs, or similar automated tasks, it’s essential to set up the access data in advance.
The output format for jsonrpc commands in opsi-cli can also be adjusted using parameters like --output-format and --attributes, similar to other opsi-cli commands. For more details on formatting options, please refer to the section Output Format.
opsi-cli --output-format table --attributes id,created,lastSeen jsonrpc execute host_getObjects '["created","lastSeen"]' '{"id":"testclient01.uib.local"}'
When using opsi-cli on Windows, be aware that the command prompt (cmd.exe) and PowerShell interpret single and double quotation marks differently. Therefore, it might be necessary to use escape sequences to ensure the commands work correctly.
|
The following examples demonstrate how to list all depots in an OPSI environment, highlighting the differences between commands on Linux/macOS and Windows. Here is how the command is executed on Linux and macOS:
opsi-cli jsonrpc execute host_getObjects [] '{"type":"OpsiDepotserver"}'
For the Windows command prompt, the command is executed as follows:
opsi-cli jsonrpc execute host_getObjects [] {\"type\":\"OpsiDepotserver\"}
In PowerShell (versions prior to 7), the command is formatted as follows:
opsi-cli jsonrpc execute host_getObjects [] '{\"type\":\"OpsiDepotserver\"}'
client-action
The client-action command is used to manage OPSI clients. It primarily offers options to influence which list of clients is affected by actions (see opsi-cli client-action --help).
It has subcommands set-action-request and trigger-event
The set-action-request subcommand requests actions for products on OPSI clients. It is comparable to the task command of opsi-admin (see section opsi-admin in Command Line Tools), but works according to the exclusion principle. This means that without explicitly specifying clients and products, the action affects everything. Therefore, set-action-request offers further options to filter the products that an action should affect (see opsi-cli client-action set-action-request --help).
The client-action command serves as a key tool in the management of OPSI clients. It primarily provides a range of options to selectively target and influence the list of clients subject to various actions:
Executing the command without specifying clients and products will affect all clients and products. To minimize the risk of errors, opsi-cli restricts the execution of set-action-request unless at least one of the following parameters is specified: --where-outdated, --where-failed, --products, or --product-groups.
|
For setting all outdated products of clients to setup, use this command:
opsi-cli client-action set-action-request --where-outdated
Alternatively, set only a specific product (here: opsi-client-agent) on a specific client (here test-98.domain.tld) to setup:
opsi-cli -l5 client-action --clients test-98.domain.tld set-action-request --products opsi-client-agent
[5] [2022-10-28 12:54:59.998] [ ] Selected clients: ['test-98.domain.tld'] (client_action_worker.py:48)
[5] [2022-10-28 12:55:00.055] [ ] Handling products ['opsi-client-agent'] (set_action_request_worker.py:105)
[5] [2022-10-28 12:55:00.065] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-98.domain.tld (set_action_request_worker.py:134)
The default product status is setup. To set the same product to uninstall, use the following command:
opsi-cli -l5 client-action --clients test-98.domain.tld set-action-request --products opsi-client-agent --request-type uninstall
[5] [2022-10-28 12:57:06.848] [ ] Selected clients: ['test-98.domain.tld'] (client_action_worker.py:48)
[5] [2022-10-28 12:57:06.904] [ ] Handling products ['opsi-client-agent'] (set_action_request_worker.py:105)
[5] [2022-10-28 12:57:06.914] [ ] Setting 'uninstall' ProductActionRequest: opsi-client-agent -> test-98.domain.tld (set_action_request_worker.py:134)
To reset an action request for a specific product on a client, use the value None (none is also allowed):
opsi-cli -l5 client-action --clients test-98.domain.tld set-action-request --products opsi-client-agent --request-type None
[5] [2022-10-28 14:12:50.538] [ ] Selected clients: ['test-98.domain.tld'] (client_action_worker.py:48)
[5] [2022-10-28 14:12:50.574] [ ] Handling products ['opsi-client-agent'] (set_action_request_worker.py:105)
[5] [2022-10-28 14:12:50.580] [ ] Setting 'None' ProductActionRequest: opsi-client-agent -> test-98.domain.tld (set_action_request_worker.py:134)
In the event of an error with a product, it’s crucial to have the capability to temporarily reverse all actions for that product on the clients. This precautionary measure helps prevent the further distribution of the faulty product:
opsi-cli client-action set-action-request --products opsi-client-agent --request-type None
Should the product become available again, error-free, at a later stage, you can reset all outdated or incorrect status information back to setup:
opsi-cli client-action set-action-request --where-outdated --where-failed
To set a specific product on a group of clients (here: testclients) to setup, type this:
opsi-cli -l5 client-action --client-groups testclients set-action-request --products opsi-client-agent
[5] [2022-10-28 13:03:24.100] [ ] Selected clients: ['test-1.domain.tld', 'test-2.domain.tld', 'test-3.domain.tld', 'test-4.domain.tld', 'test-5.domain.tld'] (client_action_worker.py:48)
[5] [2022-10-28 13:03:24.159] [ ] Handling products ['opsi-client-agent'] (set_action_request_worker.py:105)
[5] [2022-10-28 13:03:24.169] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-1.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:03:24.170] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-2.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:03:24.170] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-3.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:03:24.170] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-4.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:03:24.170] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-5.domain.tld (set_action_request_worker.py:134)
Beyond specifying a group of clients, you have the option to define a group of products (in this example: testproducts) using the --product-groups parameter:
opsi-cli -l5 client-action --client-groups testclients set-action-request --product-groups testproducts
[5] [2022-10-28 13:05:53.147] [ ] Selected clients: ['test-1.domain.tld', 'test-2.domain.tld', 'test-3.domain.tld', 'test-4.domain.tld', 'test-5.domain.tld'] (client_action_worker.py:48)
[5] [2022-10-28 13:05:53.225] [ ] Handling products ['hwaudit', 'opsi-client-agent', 'swaudit'] (set_action_request_worker.py:105)
[5] [2022-10-28 13:05:53.236] [ ] Setting 'setup' ProductActionRequest: hwaudit -> test-1.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.237] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-1.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.237] [ ] Setting 'setup' ProductActionRequest: swaudit -> test-1.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.237] [ ] Setting 'setup' ProductActionRequest: hwaudit -> test-2.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.237] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-2.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.238] [ ] Setting 'setup' ProductActionRequest: swaudit -> test-2.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.238] [ ] Setting 'setup' ProductActionRequest: hwaudit -> test-3.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.238] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-3.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.238] [ ] Setting 'setup' ProductActionRequest: swaudit -> test-3.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.239] [ ] Setting 'setup' ProductActionRequest: hwaudit -> test-4.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.239] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-4.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.239] [ ] Setting 'setup' ProductActionRequest: swaudit -> test-4.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.239] [ ] Setting 'setup' ProductActionRequest: hwaudit -> test-5.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.239] [ ] Setting 'setup' ProductActionRequest: opsi-client-agent -> test-5.domain.tld (set_action_request_worker.py:134)
[5] [2022-10-28 13:05:53.240] [ ] Setting 'setup' ProductActionRequest: swaudit -> test-5.domain.tld (set_action_request_worker.py:134)
opsi-cli automatically omits a specified list of packages when using the --where-outdated and --where-failed parameters. Currently, these packages include opsi-winst, opsi-auto-update, opsi-script, shutdownwanted, windows10-upgrade, activate-win, opsi-script-test, opsi-bootimage-local, opsi-uefi-netboot, opsi-wan-config-on, opsi-wan-config-off, opsi-winpe, win10-sysprep-app-update-blocker, and windomain.
| While it’s straightforward to exclude additional products or product groups, a safer approach is to maintain a separate product group and specify this group during execution. This strategy enables you to limit changes exclusively to this group. |
log
The log plugin allows viewing live logs from the OPSI server and clients via the OPSI-Messagebus connection.
If the specified host is not connected, an error is raised.
The plugin determines the appropriate service or host to retrieve the logs from based on the log type and requests the log file transfer.
Subcommands
-
Description: View logs for a specified host.
-
Usage:
opsi-cli log view [OPTIONS] [HOST_ID]
-
Options:
-
--log-type(default: opsiclientd): Specify the type of log to display (opsiconfd or opsiclientd). -
--live(flag): Display live log file from the client directly (only available for opsiclientd); otherwise, display the client logs stored on the server. -
--follow(flag): Continuously follow the log file for real-time updates. -
--log-level(default: 6): Specify the log level to filter (1 to 8).
-
-
Arguments:
-
HOST_ID: The ID of the host for which logs are to be displayed.
-
-
Example:
Disable color formatting with the --no-color option or by setting the NO_COLOR environment variable. Usage: opsi-cli --no-color log view [OPTIONS] HOST_ID
|
package
The package plugin for opsi-cli offers a comprehensive set of commands for managing OPSI packages.
These commands include creating, extracting, listing, installing, and uninstalling packages, providing a unified solution for package management.
Subcommands
-
Description: The
makecommand packages a source directory and saves it to a destination directory, creating a.opsipackage along with.md5and.zsyncfiles. -
Usage:
opsi-cli package make [OPTIONS] [SOURCE_DIR] [DESTINATION_DIR] -
Options:
-
-o, --overwrite(flag): Overwrite existing package if it exists. -
--follow-symlinks(flag): Follow symlinks. -
--custom-name: Include directories with the custom name. -
--custom-only(flag): Include only custom directories. -
--md5/--no-md5(flag, default: true): Create md5 checksum for the package (use--no-md5to disable). -
--zsync/--no-zsync(flag, default: true): Create zsync file for the package (use--no-zsyncto disable).
-
-
Arguments:
-
SOURCE_DIR(default: current directory): Source directory. -
DESTINATION_DIR(default: current directory): Destination directory.
-
-
Example:
-
Description: The
control-to-tomlcommand generates acontrol.tomlfile from acontrolfile located in the specified source directory. -
Usage:
opsi-cli package control-to-toml [SOURCE_DIR] -
Arguments:
-
SOURCE_DIR(default: current directory): Source directory.
-
-
Description: The
extractcommand extracts an OPSI package from the specified package archive to the destination directory. -
Usage:
opsi-cli package extract [OPTIONS] [PACKAGE_ARCHIVE] [DESTINATION_DIR] -
Options:
-
--new-product-id: A new product ID to replace the existing one in the control file. -
-o, --overwrite(flag): Overwrite destination directory if it exists.
-
-
Arguments:
-
PACKAGE_ARCHIVE: Path to the package archive. -
DESTINATION_DIR(default: current directory): Destination directory.
-
-
Example:
opsi-cli package extract <package_archive.opsi> <destination_dir>
-
Description: The
listcommand lists OPSI products installed on an OPSI-Depotserver. By default, it shows products on all depots. -
Usage:
opsi-cli package list [OPTIONS] [PRODUCT_IDS] -
Options:
-
--depots(default: all): Depot IDs (comma-separated) or 'all'. -
--product-type: Filter the output by product type [localboot|netboot].
-
-
Arguments:
-
PRODUCT_IDS: List of product IDs to filter the output. "*" can be used as a wildcard.
-
-
Example:
-
Description: The
installcommand installs OPSI packages from local paths or URLs. By default, the package is installed on the OPSI-Configserver. -
Usage:
opsi-cli package install [OPTIONS] [PACKAGES] -
Options:
-
--depots(default: OPSI-Configserver): Depot IDs (comma-separated) or 'all'. -
--update-properties(flag): Trigger an interactive prompt to update Product property default values. -
--force(flag): Force installation. -
--setup-where-installed(flag): Setup where the package is installed. -
--setup-where-installed-with-dependencies(flag): Setup where the package is installed with dependencies. -
--update-where-installed(flag): Update where the package is installed.
-
-
Arguments:
-
PACKAGES: List of packages to install, which can be specified as local paths or URLs.
-
-
Example:
-
Description: The
uninstallcommand uninstalls OPSI products specified by their product IDs. By default, it uninstalls from the OPSI-Configserver. -
Usage:
opsi-cli package uninstall [OPTIONS] [PRODUCT_IDS] -
Options:
-
--depots(default: OPSI-Configserver): Depot IDs (comma-separated) or 'all'. -
--force(flag): Force uninstallation. -
--keep-files(flag): Keep files on uninstallation.
-
-
Arguments:
-
PRODUCT_IDS: List of product IDs to uninstall.
-
-
Example:
opsi-cli package uninstall --depots <depot_id> --force <product1> <product2>
Use the --quiet option to suppress the progress bar and other non-essential output.
|
plugin
All opsi-cli commands are implemented as plugins, including the plugin command itself. You use it to manage plugins, i.e. to install new external plugins or to remove running plugins from the system. You can also use opsi-cli plugin to list or export plugins. See opsi-cli plugin --help
To generate a template for a new plugin:
opsi-cli plugin new
After you have entered the name, version, and description, opsi-cli creates a new directory using the specified name. This directory includes the subdirectories python and data:
-
The
pythondirectory is intended for the code of the new plugin. It is structured as a Python package and includes ainit.pyfile to get started. Inside, you will find an example of a command, a subcommand, and some options. -
The
datadirectory is for static resources related to the plugin; it is typically not necessary to modify this directory.
Once you have populated the template with content, proceed to add the plugin to the running opsi-cli instance:
opsi-cli plugin add <directory>
If the specified directory contains valid Python code, the command within it becomes available as a plugin in opsi-cli.
To display all registered plugins, use the command opsi-cli plugin list.
|
You can export a plugin to an archive and then import it into another opsi-cli instance:
opsi-cli plugin export <name>
opsi-cli plugin add <archive>
Use these commands to convert a directory into an archive and vice versa:
opsi-cli plugin compress <directory>
opsi-cli plugin extract <archive>
To modify an imported plugin, first unpack it using the extract command, then alter the contents of the directory, and finally call opsi-cli plugin add <directory> again. This process will replace the existing plugin with the updated version that shares the same name.
|
To remove a plugin from an opsi-cli instance, use the following command:
opsi-cli plugin remove <name>
self
Use the self command to manage the opsi-cli instance. This includes installing and uninstalling opsi-cli on the system, activating autocomplete and displaying the command structure (see opsi-cli self --help).
You can install opsi-cli on your system using the opsi-cli binary. Execute the command opsi-cli self install for this purpose. During the installation process, the binary program is copied to a globally accessible location (or included in the PATH on Windows), and a configuration file is generated. You have the option to choose between a user-specific installation or a system-wide installation with the --system option. To uninstall, use the command opsi-cli self uninstall.
If you install the OPSI package opsi-cli or opsi-utils on a client, you can skip the step opsi-cli self install.
|
To view the command structure, including all commands, their version numbers, and subcommands, enter opsi-cli self command-structure.
The opsi-cli auto-completion works for commands, subcommands and options. To set it up, enter this command:
opsi-cli self setup-shell-completion
The autocompletion feature is currently compatible with three different shells: Bash, ZSH, and Fish. Once you restart the active shell or log in anew, tab completion can be used in the same manner as in conventional Unix shells. Press [Tab] [Tab] to display all available options or commands, depending on the context. Here’s how [Tab] [Tab] functions in various scenarios:
-
When used after
opsi-clior any command with at least one subcommand, it presents a list of available (sub)commands. -
After entering
-, it shows the available options for the current command or foropsi-cliitself. -
Following a subcommand, it reveals possible values for the arguments:
-
For the subcommands
set,show, andunsetofopsi-cli config, [Tab] [Tab] generates a list of all available configurations that can be modified. -
For
opsi-cli jsonrpc execute, it displays a list of available methods, which can be filtered by a specified prefix.
-
support
The opsi-cli support command is designed to assist in diagnosing and resolving issues within your OPSI environment. Currently, it includes a single subcommand: opsi-cli support health-check. This command examines various factors that might affect the efficient operation of an OPSI environment and compiles a comprehensive report.
The following example shows a compact representation of the report.
opsi-cli support health-check
You can get a detailed report using the switch --detailed. Alternatively you can specify a category on which you want to get detailed information, like
opsi-cli support health-check system_packages
Another subcommand of opsi-cli support is client-logs, which provides the functionality to gather all opsi-related logfiles from a client. The logfiles are compressed on the client side, and the resulting archive is transferred via opsi-messagebus to the current working directory. Once transferred, the archive can be extracted, analyzed, and shared as needed.
terminal
The opsi-cli terminal command launches a basic terminal client, enabling you to establish a connection with OPSI servers. Its functionality is similar to SSH or PuTTY. To connect to an OPSI server, simply enter the OPSI host ID.
opsi-cli terminal test-1.domain.tld
Additionally, this command can be used to communicate with the OPSI config server:
opsi-cli terminal configserver
As soon as you close the terminal, either by typing the exit command or using the key combination [Ctrl]+[D], the connection will be terminated.
This command initiates the default shell on the target system and transmits inputs and outputs in real time. Therefore, typically, you will access a cmd shell on Windows, a zsh shell on MacOS, and on Linux, a shell dependent on the distribution, which is often bash.