In this tutorial am going to create and deploy a simple sate file for installing and starting apache webserver .You can have the salt file inside the /srv/salt folder. But for good file organization, create a folder named webserver inside the salt folder.

Apache package name differs with OS family. So we use python templating to provide appropriate package name using salt grains. Grains is a module which collects the static information about a minion. So , in the above code it checks if the OS is Ubuntu. If yes then apache2 package will be installed. Got redhat system , you have to define grains[‘os’] == ‘redhat’ and the package name will be httpd.

Service.running will ensure that the installed service is in running state. The service name is provided to the state using grains os check.

Now, we have a state file, which will install and start apache webserver. Let say , you have to deploy this state to one of minions in your infrastructure. Here is where top file comes in to play. Top.sls file should be present inside /srv/salt folder.

In top.sls file , we define the minions and states. Top file decides which state should be run on a particular minion or on all minions. You can define various environments inside the top file. So that , you can set specific states, which would run only in the specified environments.

Create a top.sls file inside /srv/salt folder. Top.sls for the created apache state is described below.

Base: is the default environment. Normally in base , we would define states that has to be applied on all the minions under the master.

‘jarvis’ is the minion name. If you mention * instead of Jarvis , it will include all the minions under the master.

Webserver.apache is the path to the salt state file. Webserver is the folder inside /srv/salt and apache is the identification for apache.sls file inside webserver folder.

Deploying the state on Minions:You can deploy the state on a minion from both the master and minion. In other configuration management tools like chef and puppet , you need to configure extra features like mcollective to push a configuration to a node. Push feature in salt comes by default unlike other configuration management tools.

From master:The following command deploys the state on all minions paralelly as described in the top file.