Installing SaltStack and Integrating with Jenkins for Automated Deployment
This guide walks through installing SaltStack components (salt‑master, salt‑minion, and salt‑api) on CentOS, configuring them, testing the API, and then integrating SaltStack with Jenkins by creating Jenkinsfiles that invoke Salt commands via the API or direct CLI for automated deployments.
1. Install SaltStack
For detailed SaltStack principles, refer to the official SaltStack documentation.
1.1 Install salt-master (Jenkins)
yum -y install salt-master
service salt-master start
chkconfig salt-master on1.2 Install salt-minion (application deployment machines)
yum -y install salt-minion
service salt-minion start
chkconfig salt-minion on
# Edit /etc/salt/minion to set the master address
master: 192.168.0.41
# Authenticate the client on the master node
salt-key -L
salt-key -a clientName1.3 Install salt-api (Jenkins)
yum -y install salt-api
service salt-api start
chkconfig salt-api on
# Add a system user for API operations
useradd saltapi
passwd saltapi
# Edit /etc/salt/master
file_roots: # allow Salt to serve files
base:
- /srv/salt
rest_cherrypy: # salt-api configuration
port: 9000
disable_ssl: True
debug: True
external_auth:
pam:
saltapi:
- .*
- '@wheel'
- '@runner'
service salt-master restart
service salt-api start1.4 Test
curl http://127.0.0.1:9000/login -d username='saltapi' -d password='123456' -d eauth='pam'If a token is returned, the test succeeded.
2. Integrate Jenkins
2.1 Test Salt (saltapi method)
Install the SaltStack plugin in Jenkins.
Generate a Jenkinsfile via Project → Pipeline Syntax → Snippet Generator.
Jenkinsfile example:
#!groovy
// Build parameters
String targetHosts = "${env.targetHosts}"
// Salt API template
def Salt(salthost, saltfunc, saltargs) {
result = salt(authtype: 'pam',
clientInterface: local(arguments: saltargs,
function: saltfunc,
target: salthost,
targettype: 'list'),
credentialsId: "f89abde3-49f0-4b75-917e-c4e49c483f4f",
servername: "http://0.0.0.0:9000")
println(result)
PrintMes(result,'blue')
return result
}
node("master") {
stage("Deploy") {
Salt("${targetHosts}", "cmd.run", "ls")
}
}2.2 Test Salt (command method)
Jenkinsfile:
node {
stage("Deploy") {
sh "salt * test.ping"
}
}Build the pipeline to verify the Salt command execution.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.