Skip to content

Instantly share code, notes, and snippets.

@scottwallacesh
Created November 9, 2018 09:46
Show Gist options
  • Save scottwallacesh/126c1e0dfa9c0060769e1483320aaab4 to your computer and use it in GitHub Desktop.
Save scottwallacesh/126c1e0dfa9c0060769e1483320aaab4 to your computer and use it in GitHub Desktop.
Deterministic "random" numbers filter_plugin for ansible
# 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