packagemanager-1.7.0

KOSI Plugin Packagemanager Version 1.7.0

Summary

The Packagemanager Plugin provides a possibility for managing software packages on supported Linux distributions within a KOSI package. With this plugin users can:

  • Install new software packages.
  • Update installed packages to the latest versions.
  • Remove software packages that are no longer needed.
  • List installed packages.
  • Search for available packages in the package repository.

Supported Linux Distributions

Currently, this plugin supports only CentOS and uses the YUM package manager for executing package-related operations.

Keys

Key Mandatory Description
operation Yes Defines the action to be performed. Acceptable values: install, update, remove, list, search.
packages Yes Specifies the package(s) to be managed. Multiple packages can be specified as a space-separated string.
flags Optional Optional flags for the package manager (e.g., -y for automatic confirmation, -v for verbose output).
sudo Optional Set to true to execute the command with elevated privileges. Default is false.
sudoPassword Yes (if sudo is true) Required if sudo is set to true. Specifies the password for executing commands with elevated privileges.

Examples

The following examples demonstrate different package management tasks using the Package Manager Plugin on a CentOS system.

Example 1 - Install a Package or Multiple Packages

Installs nano and containerd-1.4.10 using yum.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "install";
        packages = "nano containerd-1.4.10";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 2 - Update a Package or Multiple Packages

Updates docker and containerd to the latest versions.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "update";
        packages = "docker containerd";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 3 - Remove a Package

Removes nano from the system.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "remove";
        packages = "nano";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 4 - List Installed Packages

Lists all installed packages related to containerd.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "list";
        packages = "containerd";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 5 - Search for a Package

Searches for available kubernetes packages in the YUM repository.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "search";
        packages = "kubernetes";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 6 - Consecutive Operations with Different Flags

Performs consecutive list operations on kubeadm, one with default settings and another with additional flags.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

containers = 
{
    example = ["docker.io", "nginx", "latest"];
}

install
{  
    packagemanager
    (
        operation = "list";
        packages = "kubeadm";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );

    packagemanager
    (
        operation = "list";
        packages = "kubeadm";
        flags = "-y -v";
        sudo = "true";
        sudoPassword = "mySecurePassword";
    );
}

Example 7 - Using Packagemanager Plugin with other plugins

Using packagemanager with the osCheck, if and print plugins

This example shows the interaction of several plugins. In this example, we use the packagemanager plugin together with the osCheck, if and print plugins to check whether it is the correct operating system and to output a specific message and execute a corresponding Packagemanager operation with the packagemanager plugin:

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-packagemanager-oscheck-if-print";
description = "Example using packagemanager with oscheck and if and print";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    input = "template.yaml";
}

install
{
    osCheck
    (
        getOSVar = "os";
        getOSVersionVar = "version";
    );

    if (condition = "$os$ = 'CentOS 7'") then
    {
        print(message="Performing Packagemanager operation for CentOS 7..");

        packagemanager
        (
            operation = "install";
            packages = "nano containerd-1.4.10";
            sudo = "true";
            sudoPassword = "mySecurePassword";
        );
    }
    else
    {
        print(message="Other OS recognized instead of CentOS 7, skipping");
    }
}

Expected Behavior

If os is CentOS 7:

2025-02-26 15:18:28 Info:      Performing Packagemanager operation for CentOS 7..
  • The nano and containerd-1.4.10 software packages are installed on the machine.

Otherwise:

2025-02-26 15:18:28 Info:      Other OS recognized instead of CentOS 7, skipping
  • As we have not specified anything else in the else part of the if plugin, nothing else happens in the else part.