Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

If you are a professional associated with system and infrastructure management, looking at automated infrastructure and deployments, then this book is for you. No prior experience of Salt is required.
Table of Contents (13 chapters)
12
Index

Using grains in states


Grains are one of the most important features of Salt, based on which we can perform the configuration and orchestration tasks efficiently. Salt offers the flexibility to use the default grains and also to add custom grains as and when required. In this recipe, you will learn how to use grains in state configurations.

How to do it...

Configure a new minion with the hostname or minion ID as stgdc1app01 in the staging environment. In this naming convention, stg is the environment, dc1 is the location, app is the server type, and 01 is a numeric identifier for the host.

  1. Run the following command to get a full list of available grains on the minion:

    [root@salt-master ~]# salt 'stgdc1app01' grains.items
    
  2. Next, run the following command to get information about two specific grains that we will work with:

    [root@salt-master ~]# salt 'stgdc1app01' grains.item \ ip_interfaces fqdn
    stgdc1app01:
      fqdn: stgdc1app01
      ip_interfaces: {'lo': ['127.0.0.1'], 'eth1': ['192.168.0.3'], 'eth0...