Salt formulas are packaged and distributed to Salt masters using the package manager. This concept was influenced from RPM, Yum and Pacman packaging systems. Salt state, pillar, file templates and other files are used by the formula and then packaged into a single file.
After a formula package is created, it is copied to the Repository System to make it to use for Salt masters. Before moving to the package manager, let us have a look at how to install an “nginx” package using the Salt basic command.
The following syntax is used to install a “nginx” package.
root@saltmaster:/home/vagrant# salt '*' pkg.install nginx
Here, the pkg.install nginx command is used to install a package. After execution, you will see the following response.
It will produce the following output −
minion2: ---------- httpd: ---------- new: 1 old: httpd-cgi: ---------- new: 1 old: libxslt1.1: ---------- new: 1.1.28-2build1 old: nginx: ---------- new: 1.4.6-1ubuntu3.7 old: nginx-common: ---------- new: 1.4.6-1ubuntu3.7 old: nginx-core: ---------- new: 1.4.6-1ubuntu3.7 old: minion1: ---------- httpd: ---------- new: 1 old: httpd-cgi: ---------- new: 1 old: libxslt1.1: ---------- new: 1.1.28-2build1 old: nginx: ---------- new: 1.4.6-1ubuntu3.7 old: nginx-common: ---------- new: 1.4.6-1ubuntu3.7 old: nginx-core: ---------- new: 1.4.6-1ubuntu3.7 old:
Now, you have installed a package. To start the services for that package, use the command given below.
root@saltmaster:/home/vagrant# salt '*' service.start nginx
After running this command, the result looks as shown in the code block below.
minion1: True minion2: True
Therefore, we have installed and started the services for the “nginx” package using the basic command. Let us now discuss how to build and install packages in the Salt package manager.
Packages can be built on any system where you can install Salt. There are three type of packages and they are follows.
Let us now understand how to build packages using the Fomula File.
Most files from the package are located at the – /srv/spm/salt/ directory by default, but the pillar file can be placed in the – /srv/spm/pillar/ directory. The Formula file describes the package.
name: apache os: RedHat os_family: RedHat version: 201607 release: 2 summary: Formula for installing Apache description: Formula for installing Apache
Name − The name of the package. Here, the package name is apache.
os − It is used to know which operating systems can support this package.
os_family − It is used to know which operating system families can support this package.
Version − The version of the package. It is specified in an YYYYMM format.
Release − This field refers primarily to a release of a version.
Summary − Short lines description of the package.
Description − A more detailed description of the package.
The reactor files resides in the /srv/spm/reactor/ directory.
The files in this type of a package are configuration files for Salt, which normally live in the /etc/salt/ directory. Configuration files for packages other than Salt can and should be handled with a Salt State (using a formula type of package).
Let us continue with the following steps to build a package.
Create a FORMULA file and place it in the root of the package folder.
Assemble the formula files in a folder on the build system.
Run spm build. The package is built and placed in the /srv/spm_build folder. The following command is used to build a package.
spm build /path/to/salt-packages-source/formula
Now, copy the .spm file to a folder on the repository system.
You can share the srv/spm_build folder on the network, or copy the files to your FTP or the Webserver.
Generate repo metadata using the following command.
spm create_repo /srv/spm_build
This section explains about installing Salt package manager packages.
To configure remote repositories, the Salt Master needs to know where the repository is through a configuration process.
Files are in the /etc/salt/spm.repos.d/spm.repo directory.
file_repository: url: https://spm.example.com/
Here, the file contains the name of the repository and the link to the repository. You can also use http, https, ftp, or the file path. To use file path, you can access it using the URL: file:///srv/spm_build.
After the repository is configured on the Salt master, repository metadata is downloaded using the command below.
The SPM packages are located in the srv/spm/salt directory. Add the following path to the file roots on the Salt master,
file_roots: base: 1. /srv/salt 2. /srv/spm/salt
Now, restart the salt master.
To install the package apache, use the following command.
spm install apache
You can also install directly from the SPM file using the command below.
spm local install /srv/spm/apache-201607-1.spm
To remove a package, for example – apache, use the following command,
spm remove apache
Note that, if any files have been modified, they will not be removed.