Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Salt Cookbook
  • Toc
  • feedback
Salt Cookbook

Salt Cookbook

By : Anirban Saha
3.5 (2)
close
Salt Cookbook

Salt Cookbook

3.5 (2)
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)
close
12
Index

Listening to events


Out of the two procedures of a Salt event system, one is listening to Salt events. In this chapter, we will learn about the different procedures to listen for Salt events.

How to do it...

  1. On the Salt master, create a file anywhere called cookbookeventslisten.py and edit it so it has the following content:

    #!/usr/bin/python
    
    import salt.config
    import salt.utils.event
    import time
    import pprint
    
    opts = salt.config.client_config('/etc/salt/master')
    
    event = salt.utils.event.get_event(
            'master',
            sock_dir=opts['sock_dir'],
            transport=opts['transport'],
            opts=opts)
    
    response = event.get_event(wait=30, tag='cookbook/test')
    print('Event fired at {0}'.format(time.asctime()))
    print('*' * 25)
    print('Tag: {0}'.format(response['tag']))
    print('Data:')
    pprint.pprint(response['data'])
  2. Run the script in either of the following ways; however, there will be no output as no events have been sent yet:

    [root@salt-master ~]# ./cookbookeventslisten.py
    
    [root@salt-master...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete