Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using Python functions in conditionals


Being based on Python, one of the biggest advantages of Salt is to be able to use a lot of Salt-specific features such as functions. In this recipe, you will learn how to use Python functions in Salt to manipulate data and make efficient use of them to configure our infrastructure.

How to do it...

  1. Configure two minions, one named stgdc1app01 and another named stgdc2app01.

  2. Run the following commands to get the grains with which we will be working in this recipe:

    [root@salt-master ~]# salt 'stgdc1app01' grains.item \ ip_interfaces hwaddr_interfaces
    stgdc1app01:
      hwaddr_interfaces: {'lo': '00:00:00:00:00:00', 'eth0': '00:0c:29:ef:d5:56', 'eth1': '00:0c:29:ef:d5:4c'}
      ip_interfaces: {'lo': ['127.0.0.1'], 'eth0': ['192.168.0.2'], 'eth1': ['192.168.29.128']}
    
    [root@salt-master ~]# salt 'stgdc2app01' grains.item \ ip_interfaces hwaddr_interfaces
    stgdc2app01:
      hwaddr_interfaces: {'lo': '00:00:00:00:00:00', 'eth0': '00:0c:29:61:ea:08', 'eth1': '00:0c:29:61:ea...