Skip to content

Instantly share code, notes, and snippets.

@cchurch
Created August 5, 2015 15:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cchurch/c2694a1de478ec417ee8 to your computer and use it in GitHub Desktop.
Save cchurch/c2694a1de478ec417ee8 to your computer and use it in GitHub Desktop.
Ansible callback plugin example for rate limiting tasks
# Python
import time
class CallbackModule(object):
'''
Delay after Rackspace DNS API requests to avoid rate limit (20/minute).
'''
def _rate_limit(self):
role_name = getattr(getattr(self, 'task', None), 'role_name', '')
if role_name == 'rax-dns':
time.sleep(4) # need to wait a little longer for some reason.
def runner_on_ok(self, host, res):
self._rate_limit()
def runner_on_error(self, host, res):
self._rate_limit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment