mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
sequence will now run once for start=end, added test to suite
fixes #11979
This commit is contained in:
parent
7eaacaf66e
commit
1acb29ff9b
2 changed files with 10 additions and 10 deletions
|
@ -142,13 +142,9 @@ class LookupModule(LookupBase):
|
||||||
|
|
||||||
def sanity_check(self):
|
def sanity_check(self):
|
||||||
if self.count is None and self.end is None:
|
if self.count is None and self.end is None:
|
||||||
raise AnsibleError(
|
raise AnsibleError( "must specify count or end in with_sequence")
|
||||||
"must specify count or end in with_sequence"
|
|
||||||
)
|
|
||||||
elif self.count is not None and self.end is not None:
|
elif self.count is not None and self.end is not None:
|
||||||
raise AnsibleError(
|
raise AnsibleError( "can't specify both count and end in with_sequence")
|
||||||
"can't specify both count and end in with_sequence"
|
|
||||||
)
|
|
||||||
elif self.count is not None:
|
elif self.count is not None:
|
||||||
# convert count to end
|
# convert count to end
|
||||||
if self.count != 0:
|
if self.count != 0:
|
||||||
|
@ -166,7 +162,7 @@ class LookupModule(LookupBase):
|
||||||
raise AnsibleError("bad formatting string: %s" % self.format)
|
raise AnsibleError("bad formatting string: %s" % self.format)
|
||||||
|
|
||||||
def generate_sequence(self):
|
def generate_sequence(self):
|
||||||
if self.stride > 0:
|
if self.stride >= 0:
|
||||||
adjust = 1
|
adjust = 1
|
||||||
else:
|
else:
|
||||||
adjust = -1
|
adjust = -1
|
||||||
|
@ -187,8 +183,6 @@ class LookupModule(LookupBase):
|
||||||
for term in terms:
|
for term in terms:
|
||||||
try:
|
try:
|
||||||
self.reset() # clear out things for this iteration
|
self.reset() # clear out things for this iteration
|
||||||
|
|
||||||
term = self._templar.template(term)
|
|
||||||
try:
|
try:
|
||||||
if not self.parse_simple_args(term):
|
if not self.parse_simple_args(term):
|
||||||
self.parse_kv_args(parse_kv(term))
|
self.parse_kv_args(parse_kv(term))
|
||||||
|
|
|
@ -81,6 +81,11 @@
|
||||||
with_sequence: count=0
|
with_sequence: count=0
|
||||||
register: count_of_zero
|
register: count_of_zero
|
||||||
|
|
||||||
|
- name: test with_sequence does 1 when start == end
|
||||||
|
debug: msg='should run once'
|
||||||
|
with_sequence: start=1 end=1
|
||||||
|
register: start_equal_end
|
||||||
|
|
||||||
- name: test with_sequence count 1
|
- name: test with_sequence count 1
|
||||||
set_fact: "{{ 'x' + item }}={{ item }}"
|
set_fact: "{{ 'x' + item }}={{ item }}"
|
||||||
with_sequence: count=1
|
with_sequence: count=1
|
||||||
|
@ -88,6 +93,7 @@
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
|
- not start_equal_end| skipped
|
||||||
- count_of_zero | skipped
|
- count_of_zero | skipped
|
||||||
- not count_of_one | skipped
|
- not count_of_one | skipped
|
||||||
|
|
||||||
|
@ -97,7 +103,7 @@
|
||||||
set_fact: "random={{ item }}"
|
set_fact: "random={{ item }}"
|
||||||
with_random_choice:
|
with_random_choice:
|
||||||
- "foo"
|
- "foo"
|
||||||
- "bar"
|
- "bar"
|
||||||
|
|
||||||
- name: verify with_random_choice
|
- name: verify with_random_choice
|
||||||
assert:
|
assert:
|
||||||
|
|
Loading…
Reference in a new issue