Created
January 22, 2015 13:42
-
-
Save prune998/b6510a0132ee3cb4de6b to your computer and use it in GitHub Desktop.
uuid lookup
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
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