Configuring Salt Provisioner
1. Setting Minion Configuration
| Property | Values | Description |
|---|---|---|
| minion.config | string |
Path to the minion configuration file (e.g., /etc/salt/minion) |
| minion.id | string |
Unique identifier for the Salt minion |
| master | string |
Address of the Salt master (e.g., 192.168.50.10) |
| master_port | number |
Port the Salt master listens on (default: 4505) |
| environment | string |
Salt environment (e.g., base, prod) |
Example: Basic Minion Configuration
minion.config: /etc/salt/minion
minion.id: web01
master: 192.168.50.10
master_port: 4505
environment: base
2. Configuring Salt States
| Property | Description | Default | Notes |
|---|---|---|---|
| salt.state | Path to the Salt state file or directory | null |
Required if using salt state provisioning |
| salt.highstate | Whether to run highstate | false |
Set to true to run highstate instead of individual states |
| salt.state.highstate | Whether to run highstate (alternative) | false |
Same as salt.highstate, deprecated in favor of salt.highstate |
| salt.state.sls | List of SLS files to apply | [] |
Array of SLS file names to apply, e.g., ['nginx', 'mysql'] |
| salt.state.topfile | Path to the Salt top file | null |
Used with salt.highstate to define state topology |
| salt.state.verbose | Enable verbose output | false |
Set to true for detailed Salt output |
Example: Salt States Configuration
Vagrant.configure("2") do |config|
config.vm.provision :salt do |salt|
salt.state = "/path/to/salt/states"
salt.highstate = true
salt.state.verbose = true
end
end
Note: Salt states can be managed either via individual SLS files or through a topfile for highstate execution.
3. Using Masterless Mode
In masterless mode, Salt is configured to run without a Salt Master, directly on the Vagrant guest. This setup is useful for testing configurations or running Salt states in isolated environments.
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| masterless | Enables masterless Salt configuration | false |
Set to true to enable masterless mode |
| file_roots | Directory paths for Salt states | /srv/salt |
Must be accessible from the guest |
| pillar_roots | Directory paths for Salt pillars | /srv/pillar |
Optional, used for pillar data |
| state_top | Top file defining Salt states | top.sls |
Must be located in file_roots |
Example: Vagrantfile Configuration for Masterless Mode
# Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Salt provisioner in masterless mode
config.vm.provision :salt do |salt|
salt.masterless = true
salt.file_roots = ["/vagrant/salt"]
salt.pillar_roots = ["/vagrant/pillar"]
salt.state_top = "top.sls"
end
end
Example: Nginx State (salt/nginx.sls)
# salt/nginx.sls
nginx:
pkg.installed
nginx.service:
service.running:
- require:
- pkg: nginx
4. Setting Pillar Data
| Option | Values | Description |
|---|---|---|
| pillar | {} |
Hash of pillar data to be passed to Salt |
| pillar_file | path/to/pillar.sls |
Path to a pillar file on the host machine |
| pillar_top | path/to/top.sls |
Path to a pillar top file on the host machine |
Example: Setting Pillar Data in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.provision :salt do |salt|
salt.pillar = {
"webserver" => {
"port" => 8080,
"ssl" => true
},
"database" => {
"host" => "db.example.com",
"port" => 5432
}
}
end
end
Note: Pillar data is merged with any existing pillar data in the Salt environment.
5. Configuring Formulas
| Property | Description | Default | Notes |
|---|---|---|---|
| formulas | List of formulas to apply | Empty list | Each formula is a dictionary with name and optional parameters |
| formula_root | Root directory for formulas | /srv/formulas |
Path where formulas are stored locally |
Example: Defining Formulas
config.vm.provision :salt do |salt|
salt.formulas = [
{
name: "nginx",
version: "1.0.0"
},
{
name: "mysql",
version: "2.0.0"
}
]
end
Example: Custom Formula Root
config.vm.provision :salt do |salt|
salt.formula_root = "/custom/formulas"
salt.formulas = [
{
name: "myapp",
version: "latest"
}
]
end
6. Using Grains
| Grain | Description | Example Value |
|---|---|---|
| os | Operating system family | RedHat, Debian |
| os_family | Operating system family | RedHat, Debian |
| osfinger | Operating system fingerprint | CentOS-7, Ubuntu-20.04 |
| osrelease | Operating system release version | 7, 20.04 |
| arch | Architecture of the system | x86_64, armv7l |
| fqdn | Fully qualified domain name | web01.example.com |
| hostname | Hostname of the system | web01 |
| id | Unique identifier for the minion | web01.example.com |
Example: Setting grains in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.provision :salt do |salt|
salt.grains = {
"environment" => "development",
"role" => "web_server"
}
end
end
Note: Grains are static data that Salt uses to identify and classify minions. They are typically set once during minion configuration or via the Salt CLI.
7. Setting Bootstrap Options
| Option | Values | Description |
|---|---|---|
| bootstrap | true | false |
Whether to run the Salt bootstrap script. Defaults to true. |
| bootstrap_options | string |
Additional options to pass to the Salt bootstrap script. Example: -D for debug mode. |
| bootstrap_url | string |
URL to the Salt bootstrap script. Defaults to https://bootstrap.saltstack.com. |
Example: Setting Bootstrap Options
{
"bootstrap": true,
"bootstrap_options": "-D",
"bootstrap_url": "https://bootstrap.saltstack.com"
}
8. Configuring Log Level
| Option | Values | Description |
|---|---|---|
| log_level | debug, info, warn, error |
Sets the logging level for Salt provisioner output |
Example: Setting Log Level to Debug
Vagrant.configure("2") do |config|
config.vm.provision :salt do |salt|
salt.log_level = "debug"
end
end
9. Running Highstate
| Command | Description | Notes |
|---|---|---|
| vagrant provision | Runs the Salt provisioner's highstate on the VM | Executes the Salt state defined in the Vagrantfile or salt states directory |
| vagrant provision --provision-with=salt | Runs only the Salt provisioner, skipping other provisioners | Useful when multiple provisioners are defined in the Vagrantfile |
Note: The Salt provisioner must be properly configured in the Vagrantfile for this command to execute successfully.
10. Installing Salt Version
| Option | Values | Notes |
|---|---|---|
| salt.version | "3005.1" |
Latest stable Salt version |
| salt.bootstrap | true |
Enable Salt Bootstrap script |
| salt.bootstrap_url | "https://bootstrap.saltproject.io" |
URL to Salt Bootstrap installer |
Example: Install Salt 3005.1
salt.version = "3005.1"
salt.bootstrap = true
salt.bootstrap_url = "https://bootstrap.saltproject.io"
Note: Ensure the Salt version is compatible with your OS and system requirements.