Remote Client Administration: An Introduction to Client Actions with opsi-cli

Remote Client Administration: An Introduction to Client Actions with _opsi-cli_

Setting Action Requests with opsi-cli

The command line tool opsi-cli is available for Linux, Windows, and macOS. It works as a client component outside the opsi server and communicates via the opsi web service and/or opsi messagebus. opsi-cli is really useful in situations when you don’t want to use a graphical user interface, like the opsi-configed or the Web GUI. The opsi-cli command client-action offers a convenient way to set action requests for clients via the sub-command set-action-request.

Let’s look at our first example. The following command sets the action request setup (which is the default) for the hwaudit and swaudit packages on all clients:

opsi-cli client-action --clients=all set-action-request --products=hwaudit,swaudit

It’s easy to limit the pool of affected clients. Either use --clients or --client-groups and supply a list of comma-separated names. The next example sets the action request only for opsi clients which belong to the testgroup group:

doerrer@me:~$ opsi-cli -l 5 client-action --client-groups=testgroup set-action-request --products=hwaudit
[5] [2023-03-01 12:16:23.922] [               ] Selected clients: ['client-linux.domain.local', 'client-win10.domain.local']   (client_action_worker.py:56)
[5] [2023-03-01 12:16:23.972] [               ] Handling products ['hwaudit']   (set_action_request_worker.py:120)
[5] [2023-03-01 12:16:23.982] [               ] Setting 'setup' ProductActionRequest: hwaudit -> client-linux.domain.local   (set_action_request_worker.py:158)
[5] [2023-03-01 12:16:23.982] [               ] Setting 'setup' ProductActionRequest: hwaudit -> client-win10.domain.local   (set_action_request_worker.py:158)

Tip

To actually print those messages in the console, we’ve set the log level to 5, using the -l switch.

You can specify the type of action request with the --request-type parameter. As mentioned before, the default is setup. To reset an action request, use --request-type=none. This comes in handy when you want to remove action requests you set by mistake. The screenshot illustrates this: the first action request is setup for the localboot product opsi-client-agent on the opsi client client-linux.domain.local, followed by a command which revokes this with --request-type=none. The third command sets the action request for a Windows client.

opsi-cli enables to perform client actions called from your linux, macos or windows machine

Keeping Packages Up to Date on your Clients

You can also use set-action-request to perform more complex tasks. The parameter --where-outdated affects all products installed on a client which has a newer version available in the associated software depot. This way you can use opsi-cli client-action to insure that software on the clients is up to date. You can use the following parameters to select the clients:

  • --clients: comma-separated list of client names or all
  • --client-groups: comma-separated list of host groups
  • --exclude-clients: do not perform actions on these clients
  • --exclude-client-groups: do not perform actions on these host groups

The following example demonstrates how to set all outdated products to setup on all clients, except the ones in the testgroup group:

opsi-cli -l 5 client-action --clients=all --exclude-client-groups=testgroup set-action-request --where-outdated

Similarly, you can exclude specific products or product groups using --products, --product-groups, --exclude-products, and --exclude-product-groups.

Tip

Please note that there is a list of products which are always excluded for these types of calls, including all netboot products, opsi-script, opsi-auto-update, windomain, etc.

Retrying failed Installations

Correspondingly, you can retry product installations with the parameter --where-failed. It sets a new action request for all products which have the status failed.

The following example sets the product runastest to setup on all clients where the previous installation failed:

doerrer@me:~$ opsi-cli -l 5 client-action --clients=all set-action-request --where-failed --products=runastest
[5] [2023-03-01 13:58:52.715] [               ] Selected clients: ['client-linux.domain.local', 'client-macos.domain.local', 'client-win10.domain.local']   (client_action_worker.py:56)
[5] [2023-03-01 13:58:52.777] [               ] Handling products ['runastest']   (set_action_request_worker.py:120)
[5] [2023-03-01 13:58:52.788] [               ] Setting 'setup' ProductActionRequest: runastest -> client-win10.domain.local   (set_action_request_worker.py:158)

This is useful in test environments or in case some dependencies were missing when the product was first installed.

Tips & Tricks for client-action

In this last paragraph, we’ve collected some tips and tricks for you:

  • If you want to learn about available options of a command, call it with the parameter --help.
  • You can use cron to set up a schedule for opsi-cli commands on a Linux server (see chapter scheduling installations).
  • If you’ve written your own scripts to regularly update packages in your depot, you can simply include opsi-cli client-action set-action-request --where-outdated to run the update on your clients as soon as possible.
  • For a full list of commands, parameters, and options, please read our documentation (see chapter opsi command line tools and processes).

Happy tinkering!

Related Posts

opsi at T-DOSE 2023: A personal Report

opsi at T-DOSE 2023: A personal Report

On the 22nd and 23rd of April, T-DOSE 2023 took place at its new location, the Weeffabriek in Geldrop, near Eindhoven. Together with my colleague Terry Strooband, I was happy to present opsi at the Technical Dutch Open Source Event.

Read More
opsi at it-sa 2023: A Recap of a Highly Successful Exhibition

opsi at it-sa 2023: A Recap of a Highly Successful Exhibition

From October 10th to 12th 2023 the it-sa Expo&Congress took place in Nuremberg. Once again, we proudly participated as an exhibitor at Europe’s premier IT security trade fair, showcasing opsi in its fresh, new design.

Read More
Simplifying Remote Administration: An Introduction to JSON-RPC and opsi-cli

Simplifying Remote Administration: An Introduction to JSON-RPC and opsi-cli

Are you looking for a more efficient way to access your opsi server remotely? This blog post explores the benefits of JSON-RPC, a stateless and lightweight protocol which simplifies the transmission of data between a server and a client.

Read More