pkg-related module of saltstack module

1. pkg.available_version module

pkg.available_version: Returns the latest version of the queried package that can be installed or updated. If multiple packages are specified, the returned results are output in the form of a dictionary.

[root@salt-master ~]# salt '*' pkg.available_version httpd
salt-minion02.contoso.com:
    2.2.15-59.el6.centos
salt-minion01.contoso.com:
    2.2.15-59.el6.centos
[root@salt-master ~]# salt '*' pkg.available_version httpd nginx pcre
salt-minion02.contoso.com:
    ----------
    httpd:
        2.2.15-59.el6.centos
    nginx:
        1.10.2-1.el6
    pcre:
        7.8-7.el6
salt-minion01.contoso.com:
    ----------
    httpd:
        2.2.15-59.el6.centos
    nginx:
        1.10.2-1.el6
    pcre:
        7.8-7.el6
[root@salt-master ~]# salt '*' pkg.available_version nginx fromrepo=epel
salt-minion02.contoso.com:
    1.10.2-1.el6
salt-minion01.contoso.com:
    1.10.2-1.el6


2. pkg.version module

pkg.version: Returns the version number of the minion-side package, and returns empty if the package is not installed. If multiple packages are queried at the same time, the name and version number of the packages are returned as a dictionary.

[root@salt-master ~]# salt '*' pkg.version lrzsz
salt-minion01.contoso.com:
    0.12.20-27.1.el6
salt-minion02.contoso.com:
    0.12.20-27.1.el6
[root@salt-master ~]# salt '*' pkg.version lrzsz gcc
salt-minion01.contoso.com:
    ----------
    gcc:
        4.4.7-17.el6
    lrzsz:
        0.12.20-27.1.el6
salt-minion02.contoso.com:
    ----------
    gcc:
        4.4.7-17.el6
    lrzsz:
        0.12.20-27.1.el6

3. pkg.list_pkgs module

pkg.list_pkgs: Lists installed packages and returns a dictionary containing package names and version numbers.

[root@salt-master ~]# salt 'salt-minion01.contoso.com' pkg.list_pkgs
salt-minion01.contoso.com:
    ----------
    ConsoleKit:
        0.4.1-3.el6
    ConsoleKit-libs:
        0.4.1-3.el6
    ConsoleKit-x11:
        0.4.1-3.el6
    GConf2:
        2.28.0-6.el6
    MAKEDEV:
        3.24-6.el6
    ORBit2:
        2.14.17-3.2.el6_3
    PyYAML:
        3.10-3.1.el6
.....

4. pkg.install module

pkg.install: Install the corresponding package, add refresh=True to clean up the yum database before installation.

     Name: The name of the package, such as salt'*'pkg. install httpd

Refresh: Do you update the yum database before performing installation operations, such as salt'*'pkg. install httpd refresh = True

Resttall: Decides whether to reinstall the specified package by specifying the value True/False of the reinstall, which is equivalent to the yum reinstall operation. If the version of the package is specified, Yum reinstall can only be used if the specified version number is the same as the installed version number. It can be used with source, provided that the header of the source of the package matches the name and version number of the installed package.

Skp_verify: Skip GPG checking, with the -- nogpgcheck option of yum install.

Version: Specify the version of the installation package. If both "pkgs" and "sources" options are passed, the version parameter is invalid.

Repository related options:

  fromrepo: Specify from which repo repo repository to install.

   enablerepo: Enable repo repositories that have been disabled.

Disable repo: Disable repo repositories that have been enabled.

   Disable excludes: Disable references from main, perhaps repo or other references, equivalent to Yum -- Disable excludes ='main'.

Batch Installation Package Options:

   pkgs: To specify a list of software to be installed from repo repositories, you need to pass a Python list. You can specify the version number of the package by using a single dictionary containing the package and version.

 For example: salt'*'pkg. install pkgs=' ["lrzsz", "tree"]'

                salt '*' pkg.install pkgs='["gcc", {"lrzsz": "0.12.20-27.1.el6"}]'

         sources: List of RPM packages to install. A dictionary list must be passed, containing the key of the RPM package name, and the source URL or local path of the RPM package as the key value.

 For example, salt'*'pkg.install sources='[{foo":"salt://foo.rpm"}, {bar": "salt://bar.rpm"}''

The relevant examples are as follows:

[root@salt-master ~]# salt 'salt-minion01.contoso.com' pkg.install tcpdump
salt-minion01.contoso.com:
    ----------
    tcpdump:
        ----------
        new:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
        old:
            14:4.0.0-3.20090921gitdf3cb4.2.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.install tcpdump refresh=True
salt-minion02.contoso.com:
    ----------
    tcpdump:
        ----------
        new:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
        old:
            14:4.0.0-3.20090921gitdf3cb4.2.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.install tcpdump reinstall=True
salt-minion02.contoso.com:
    ----------
    tcpdump:
        ----------
        new:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
        old:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.install pcre fromepel=epel   #Instead of installing with fromrepo, you can install with the fromepel = option (the salt version used is salt-master-2015.5.10-2.el6.noarch)
salt-minion02.contoso.com:
    ----------
    pcre:
        ----------
        new:
            7.8-7.el6
        old:
            7.8-6.el6
[root@salt-master ~]# salt 'salt-minion01.contoso.com' pkg.install nfs-utils fromepel=CentOS-Base
salt-minion01.contoso.com:
    ----------
    libtirpc:
        ----------
        new:
            0.2.1-13.el6_9
        old:
            0.2.1-6.el6_4
    nfs-utils:
        ----------
        new:
            1:1.2.3-75.el6
        old:
            1:1.2.3-39.el6
    python-argparse:
        ----------
        new:
            1.2.1-2.1.el6
        old:
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.install pkgs='["lrzsz","tree"]' re
install=True
salt-minion02.contoso.com:
    ----------
    lrzsz:
        ----------
        new:
            0.12.20-27.1.el6
        old:
            0.12.20-27.1.el6
    tree:
        ----------
        new:
            1.5.3-3.el6
        old:
            1.5.3-3.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.install sources='[{"zabbix-release": "http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm"}]'
salt-minion02.contoso.com:
    ----------
    zabbix-release:
        ----------
        new:
            3.0-1.el6
        old:

5. pkg.upgrade module

pkg.upgrade: Update the installed software package of the system and return a dictionary containing the new and old versions before and after registration and upgrade. Usage: salt'*'pkg.upgrade (because upgrading the system is time-consuming, no demonstration examples will be added here)

     Repository option:

     fromrepo: Specify from which repo repo repository to install.

enablerepo: Enable repo repositories that have been disabled.

disablerepo: Disable repo repositories that have been enabled.

Disable excludes: Disable references from main, perhaps repo or other references, equivalent to Yum -- Disable excludes ='main'.

6. pkg. remote module

pkg.remove: Remove packages

     name: specifies the package to be removed.

Batch Removal Options:

   pkgs: Specifies a list of packages to be removed in batches. A Python list must be passed in, and if this option is enabled, the name option is ignored.

[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.remove lrzsz
salt-minion02.contoso.com:
    ----------
    lrzsz:
        ----------
        new:
        old:
            0.12.20-27.1.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.remove tcpdump,lrzsz
salt-minion02.contoso.com:
    ----------
    lrzsz:
        ----------
        new:
        old:
            0.12.20-27.1.el6
    tcpdump:
        ----------
        new:
        old:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
[root@salt-master ~]# salt 'salt-minion02.contoso.com' pkg.remove pkgs='["tcpdump","lrzsz","tree"]'
salt-minion02.contoso.com:
    ----------
    lrzsz:
        ----------
        new:
        old:
            0.12.20-27.1.el6
    tcpdump:
        ----------
        new:
        old:
            14:4.0.0-11.20090921gitdf3cb4.2.el6
    tree:
        ----------
        new:
        old:
            1.5.3-3.el6


Keywords: yum RPM CentOS Zabbix

Added by Aphp73 on Tue, 25 Jun 2019 21:09:18 +0300