|
|
@ -152,15 +152,26 @@ class LookupModule(LookupBase):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
elif self.count is not None:
|
|
|
|
elif self.count is not None:
|
|
|
|
# convert count to end
|
|
|
|
# convert count to end
|
|
|
|
|
|
|
|
if self.count != 0:
|
|
|
|
self.end = self.start + self.count * self.stride - 1
|
|
|
|
self.end = self.start + self.count * self.stride - 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.start = 0
|
|
|
|
|
|
|
|
self.end = 0
|
|
|
|
|
|
|
|
self.stride = 0
|
|
|
|
del self.count
|
|
|
|
del self.count
|
|
|
|
if self.end < self.start:
|
|
|
|
if self.stride > 0 and self.end < self.start:
|
|
|
|
raise AnsibleError("can't count backwards")
|
|
|
|
raise AnsibleError("to count backwards make stride negative")
|
|
|
|
|
|
|
|
if self.stride < 0 and self.end > self.start:
|
|
|
|
|
|
|
|
raise AnsibleError("to count forward don't make stride negative")
|
|
|
|
if self.format.count('%') != 1:
|
|
|
|
if self.format.count('%') != 1:
|
|
|
|
raise AnsibleError("bad formatting string: %s" % self.format)
|
|
|
|
raise AnsibleError("bad formatting string: %s" % self.format)
|
|
|
|
|
|
|
|
|
|
|
|
def generate_sequence(self):
|
|
|
|
def generate_sequence(self):
|
|
|
|
numbers = xrange(self.start, self.end + 1, self.stride)
|
|
|
|
if self.stride > 0:
|
|
|
|
|
|
|
|
adjust = 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
adjust = -1
|
|
|
|
|
|
|
|
numbers = xrange(self.start, self.end + adjust, self.stride)
|
|
|
|
|
|
|
|
|
|
|
|
for i in numbers:
|
|
|
|
for i in numbers:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -191,13 +202,13 @@ class LookupModule(LookupBase):
|
|
|
|
raise AnsibleError("unknown error parsing with_sequence arguments: %r. Error was: %s" % (term, e))
|
|
|
|
raise AnsibleError("unknown error parsing with_sequence arguments: %r. Error was: %s" % (term, e))
|
|
|
|
|
|
|
|
|
|
|
|
self.sanity_check()
|
|
|
|
self.sanity_check()
|
|
|
|
|
|
|
|
if self.stride != 0:
|
|
|
|
results.extend(self.generate_sequence())
|
|
|
|
results.extend(self.generate_sequence())
|
|
|
|
except AnsibleError:
|
|
|
|
except AnsibleError:
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
except Exception:
|
|
|
|
except Exception as e:
|
|
|
|
raise AnsibleError(
|
|
|
|
raise AnsibleError(
|
|
|
|
"unknown error generating sequence"
|
|
|
|
"unknown error generating sequence: %s" % e
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return results
|
|
|
|
return results
|
|
|
|