Created
August 5, 2015 15:03
-
-
Save cchurch/c2694a1de478ec417ee8 to your computer and use it in GitHub Desktop.
Ansible callback plugin example for rate limiting tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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