Skip to content

Instantly share code, notes, and snippets.

@prune998
Created January 22, 2015 13:42
Show Gist options
  • Save prune998/b6510a0132ee3cb4de6b to your computer and use it in GitHub Desktop.
Save prune998/b6510a0132ee3cb4de6b to your computer and use it in GitHub Desktop.
uuid lookup
This is a working version :
from ansible import utils, errors
import random, string
class LookupModule (object):
""" This lookup generate a UUID of the length specified by the term
Usage:
set_fact: container_id="{{ lookup('uuid',32) }}"
"""
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
ret = []
ret.append(''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(terms)))
return ret
this is a non working version :
from ansible import utils, errors
import uuid
class LookupModule (object):
""" This lookup generate a UUID of the length specified by the term
Usage:
set_fact: container_id="{{ lookup('uuid','') }}"
"""
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
ret = []
ret.append(str(uuid.uuid1().hex))
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment