fix issue in random_mac filter with short prefixes (#53928)

This commit is contained in:
Anton Roman 2019-03-26 18:49:23 +01:00 committed by Sam Doran
commit 1e3428a766
3 changed files with 9 additions and 3 deletions

View file

@ -36,7 +36,7 @@ import yaml
import datetime
from functools import partial
from random import Random, SystemRandom, shuffle, random
from random import Random, SystemRandom, shuffle, randint
from jinja2.filters import environmentfilter, do_groupby as _do_groupby
@ -555,8 +555,8 @@ def random_mac(value):
if len(err):
raise AnsibleFilterError('Invalid value (%s) for random_mac: %s' % (value, err))
# Generate random float and make it int
v = int(random() * 10.0**10)
# Generate random int between x1000000000 and xFFFFFFFFFF
v = randint(68719476736, 1099511627775)
# Select first n chars to complement input prefix
remain = 2 * (6 - len(mac_items))
rnd = ('%x' % v)[:remain]