Deploying packages through SaltStack:
This blog will helps you with step by step instruction to Deploying packages through SaltStack . There are two ways to install packages.
1 -> Single Command & State File
INSTALLING PACKAGES THROUGH SINGLE COMMAND
- First, execute the command salt ‘saltclient‘ pkg.install net-tools
- In this demo, We are going to installing ‘netstat’ and ‘lsof’ commands from the salt-master using ‘Single command’.
- Then execute salt ‘saltclient’ pkg.installed lsof
- Before installing status:
- Installing from salt-master:
- After installing/verifying on the ‘saltclient’ VM:
2 -> Installing Packages Through state file
- A base environment is required to house the top file/state files, so we need to set the ‘file_roots’ in the salt-master configuration file ( /etc/salt/master ) and restart the salt-master service.
- Also we need to create directory ‘salt’ under ‘/srv’ ( /srv/salt )
- Execute this command : cd /srv/ ; mkdir salt
- # vi /etc/salt/master
- Restart the service using systemctl restart salt-master command
- We have created ‘apache.sls’ under the /srv/salt, lets check the contents,
apache: # ID declaration
pkg: # state declaration
– installed # function declaration
- On the apache.sls, we have used ‘pkg.installed’ instead of ‘pkg.install’ for Apache installation. Pkg.installed in the state file will help us to ensure that the package is installed with a correct version. If the package is already available it shows ‘Package already installed and its version’ else it will perform the installation.
- Before executing the state file on our minion we need to verify status.
- Well, we can start the installation from salt-master using below command.
# salt ‘saltclient‘ state.sls apache
- In meantime, we got the below result on the saltclient’s process using top command.
- Installed result on salt-master:
- After executing the state file on our minion:
- Once Apache installed, we need to start the service.
- We are going to trigger the state file ( apache.sls ) on the minion again to check the pkg.installed function’s result if the pkg already installed on the target/minion.
Thanks for visiting this article. We hope it will be useful for your to install the packages through SALT application.