Nov 18, 2025

How to use Packer with SaltStack for provisioning?

Leave a message

Packer is a powerful open - source tool developed by HashiCorp that enables users to create identical machine images for multiple platforms from a single source configuration. SaltStack, on the other hand, is a robust infrastructure automation and management solution that allows for easy configuration management, remote execution, and orchestration. In this blog post, as a Packer supplier, I will guide you on how to use Packer with SaltStack for provisioning.

Understanding the Basics

Before diving into the integration, it's crucial to understand what each tool brings to the table. Packer works by building machine images for various platforms such as Amazon EC2, Google Compute Engine, VMware, and more. It uses a JSON - based configuration file to define the build process, including the base image, provisioners, and post - processors.

SaltStack, also known as Salt, is a high - performance configuration management and remote execution system. It can manage servers, desktops, and other devices efficiently. Salt uses a master - minion architecture, where the master controls and manages multiple minions.

Prerequisites

To follow along with this guide, you need to have the following installed:

  1. Packer: You can download the latest version of Packer from the official HashiCorp website.
  2. SaltStack: Install SaltStack on your local machine. The installation process may vary depending on your operating system. For example, on Ubuntu, you can use the following commands:
wget -O - https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
echo "deb https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest focal main" | sudo tee /etc/apt/sources.list.d/saltstack.list
sudo apt-get update
sudo apt-get install salt-master salt-minion

Integrating Packer with SaltStack

The integration of Packer and SaltStack involves using SaltStack as a provisioner in Packer. Here are the steps to achieve this:

86a13c0fab0f45d7a7c97567d5063c2bCompression Open Hole Packer

Step 1: Create a Packer Configuration File

Create a new JSON file, for example, packer_salt.json. This file will define the build process.

{
    "builders": [
        {
            "type": "amazon-ebs",
            "access_key": "YOUR_AWS_ACCESS_KEY",
            "secret_key": "YOUR_AWS_SECRET_KEY",
            "region": "us - west - 2",
            "source_ami": "ami - 0c55b159cbfafe1f0",
            "instance_type": "t2.micro",
            "ssh_username": "ubuntu",
            "ami_name": "packer - salt - {{timestamp}}"
        }
    ],
    "provisioners": [
        {
            "type": "salt - masterless",
            "local_state_tree": "salt/roots",
            "local_pillar_roots": "salt/pillar"
        }
    ]
}

In the above configuration:

  • The builders section defines the type of machine image we are building (in this case, an Amazon EBS image).
  • The provisioners section specifies that we are using the salt - masterless provisioner. The local_state_tree and local_pillar_roots point to the directories where our SaltStack states and pillars are stored.

Step 2: Set Up SaltStack States and Pillars

Create the salt/roots and salt/pillar directories in your project directory.

States: States in SaltStack define the desired state of the system. For example, create a file salt/roots/top.sls with the following content:

base:
  '*':
    - apache

This file tells SaltStack to apply the apache state to all minions. Now, create a file salt/roots/apache.sls to install and start the Apache web server:

apache:
  pkg.installed:
    - name: apache2
  service.running:
    - name: apache2
    - enable: True

Pillars: Pillars are used to store sensitive data or data that is specific to a particular minion. Create a file salt/pillar/top.sls:

base:
  '*':
    - example_pillar

And salt/pillar/example_pillar.sls:

example_variable: "This is an example variable"

Step 3: Run the Packer Build

Run the following command in your terminal to start the Packer build:

packer build packer_salt.json

Packer will create an EC2 instance, install SaltStack on it, and apply the states and pillars we defined. Once the build is complete, it will create an Amazon Machine Image (AMI) that is configured with our desired settings.

Benefits of Using Packer with SaltStack

  1. Consistency: By using Packer and SaltStack together, you can ensure that all your machine images are built with the same configuration. This eliminates the problem of "works on my machine" and provides a consistent environment across different platforms.
  2. Automation: The entire process of building and provisioning machine images can be automated. This saves time and reduces the risk of human error.
  3. Scalability: You can easily scale your infrastructure by creating identical machine images and deploying them across multiple servers.

Different Types of Packers We Offer

As a Packer supplier, we offer a variety of packers for different applications. Here are some of our popular products:

  • Electrical Submersible Pump Packer: This packer is designed for use in electrical submersible pump systems. It provides a reliable seal and helps prevent fluid leakage.
  • Dragging Frac Packer: Ideal for fracturing operations, this packer can withstand high pressures and is easy to install and remove.
  • Compression Open Hole Packer: This packer is suitable for open - hole applications. It uses compression to create a tight seal and is highly effective in preventing fluid migration.

Contact Us for Procurement

If you are interested in our packer products or need more information on using Packer with SaltStack for your provisioning needs, we encourage you to contact us for a procurement discussion. Our team of experts is ready to assist you in finding the best solutions for your requirements.

References

  • HashiCorp. (n.d.). Packer Documentation. Retrieved from https://www.packer.io/docs
  • Salt Project. (n.d.). SaltStack Documentation. Retrieved from https://docs.saltproject.io/en/latest/
Send Inquiry