sh-1.7.0
2 minute read
KOSI Plugin sh Version 1.7.0
Summary
The sh
plugin is used to execute shell commands. It allows users to define commands that will be executed in a shell environment during the execution of a kosi package. This plugin is useful for automating system administration tasks, configuring environments, or executing necessary shell operations within a controlled setup.
It supports executing single commands as well as multiple commands separated by a semicolon (;
). Additionally, the plugin provides an option to execute commands with elevated privileges (sudo
).
Keys
Key | Description | |
---|---|---|
command | Mandatory | Contains a string representing a shell command or a sequence of commands to be executed. Multiple commands can be specified, separated by a semicolon (; ). |
sudo | Optional | Set to true to execute the plugin with sudo privileges. |
sudoPassword | Mandatory if you use sudo | Set sudo password. Only required, if the key sudo is set to true . |
Examples
Example 1 - Execute a single command
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-shell-package";
description = "kosi-example-shell-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
input = "template.yaml";
}
install
{
sh(command = "echo hello world");
}
Example 2 - Execute multiple commands
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-shell-package";
description = "kosi-example-shell-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
input = "template.yaml";
}
install
{
sh(command = "echo foo; echo bar");
}
Example 3 - Execute command with sudo
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-shell-package";
description = "kosi-example-shell-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
input = "template.yaml";
}
install
{
sh(
command = "reboot now";
sudo = "true";
sudoPassword = "topsecret";
);
}
Example 4 - Using sh
with the set
and if
plugins
This example shows the interaction of several plug-ins.
In this example, we use the sh
plugin together with the set
and if
plugins to check a condition (which is set before) before executing a shell command:
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-shell-if";
description = "Example using sh with set and if";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
input = "template.yaml";
}
install
{
set
(
variable = "myVar";
value = "Hello";
);
if (condition = "$vars.myVar$ = 'Hello'") then
{
sh(command = "echo Variable is 'Hello'");
}
else
{
sh(command = "echo Variable is not 'Hello'");
}
}
Expected Output
If myVar
is Hello
:
2025-02-26 15:18:28 Info: Variable is 'Hello'
If myVar
is not Hello
:
2025-02-26 15:18:28 Info: Variable is not 'Hello'