Installing Packages with Salt: Single Command & State File Method
When working with SaltStack for automation and configuration management, managing package installations is a core task. In this guide, we’ll walk you through two efficient methods for installing Packages with Salt: using a single command and through a state file. These techniques help automate installations, ensure consistency, and improve your infrastructure management.

Method 1: Installing Packages with a Single Command
The simplest way to install packages with Salt is by using a single command directly from the Salt-master. This method is quick, easy, and ensures that packages like netstat and lsof are installed across all minions. Follow these steps:
- Execute the following commands on your Salt-master:
# salt 'minion1' pkg.install net-tools # salt 'minion1' pkg.installed lsof - Verify the installation on the ‘minion1’ VM:
# which netstat # which lsof
By using this method, you can easily install and verify packages in a single step, without needing to configure any files.
Method 2: Installing Packages Through a State File
While installing packages with a single command is quick, using state files offers more control, particularly for ensuring packages are installed with specific versions. Here’s how to do it:
Step 1: Configure the Salt-Master
Before you can use state files, configure your Salt-master by setting the file_roots in the /etc/salt/master configuration file. This setup allows the Salt-master to reference the correct state files for installations. After making the necessary configuration changes, restart the Salt-master service.
# cd /srv/
# mkdir salt
# systemctl restart salt-master
Step 2: Create the Apache State File
Create the state file under /srv/salt to define the packages you want to install. For instance, we can create an Apache installation state file named apache.sls.
# cat apache.sls
install_httpd:
pkg.installed:
- name: httpd
Understanding the Syntax:
- apache: The ID declaration that specifies what the state is named.
- pkg: The state declaration that tells Salt what action to take.
- installed: Ensures the package is installed with the correct version.
The pkg.installed function is key, as it ensures that the package is installed only if it is not already present or if an update is required.
Step 3: Apply the State File
Once you’ve created the apache.sls file, use the following command to apply the state and install Apache:
# salt 'minion1' state.sls apache
After the installation, you can start the service with:
# systemctl start httpd
Why Use Salt for Package Management?
Salt’s automation capabilities extend far beyond simple package management. With features like DevOps, DevSecOps, and DataOps, you can seamlessly integrate package management into broader infrastructure management strategies. ZippyOPS provides specialized consulting and implementation services in these areas, helping businesses streamline their operations through Cloud, Automated Ops, AIOps, MLOps, Microservices, and more.
If you’re interested in exploring how SaltStack can enhance your DevOps or infrastructure management, check out our services or solutions. Whether you’re managing software packages or setting up an entire cloud infrastructure, ZippyOPS can guide you through every step of the process.
Conclusion: Streamline Your Management Packages with Salt
Using Packages with Salt management allows you to automate installations efficiently, ensuring consistency across all environments. By leveraging state files, you gain more control over package versions and configurations, while single commands provide quick solutions for immediate needs.
ZippyOPS can further help you with the implementation of Salt in your DevOps, cloud, or automated operations strategies. Reach out to us at sales@zippyops.com to learn more about how we can enhance your infrastructure management.



