Created
November 9, 2018 09:46
-
-
Save scottwallacesh/126c1e0dfa9c0060769e1483320aaab4 to your computer and use it in GitHub Desktop.
Deterministic "random" numbers filter_plugin for ansible
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
# vim: set ft=python: | |
"""Deterministic "random" numbers jinja filter for ansible. | |
Place in filter_plugins/ to use. | |
""" | |
import random | |
def determrand(high, seed, low=0): | |
"""{{60|determrand(ansible_fqdn)}}""" | |
return random.Random(seed).randint(low, high-1) | |
class FilterModule(object): | |
"""Hook filter up to ansible template processing.""" | |
def filters(self): | |
"""Return list of filters provided by module.""" | |
return {'determrand': determrand} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment