mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Don't ignore a duplicate host for an already processed include (#40361)
* Don't ignore a duplicate host for an already processed include, assume that the repetition indicates a new include. Fixes #40317 * Add intg tests to ensure duplicate items in loop are not deduped * Add note about relative indexing
This commit is contained in:
@@ -44,6 +44,8 @@ class IncludedFile:
|
||||
def add_host(self, host):
|
||||
if host not in self._hosts:
|
||||
self._hosts.append(host)
|
||||
return
|
||||
raise ValueError()
|
||||
|
||||
def __eq__(self, other):
|
||||
return other._filename == self._filename and other._args == self._args and other._task._parent._uuid == self._task._parent._uuid
|
||||
@@ -160,12 +162,24 @@ class IncludedFile:
|
||||
|
||||
inc_file = IncludedFile(role_name, include_variables, new_task, is_role=True)
|
||||
|
||||
try:
|
||||
pos = included_files.index(inc_file)
|
||||
inc_file = included_files[pos]
|
||||
except ValueError:
|
||||
included_files.append(inc_file)
|
||||
idx = 0
|
||||
orig_inc_file = inc_file
|
||||
while 1:
|
||||
try:
|
||||
pos = included_files[idx:].index(orig_inc_file)
|
||||
# pos is relative to idx since we are slicing
|
||||
# use idx + pos due to relative indexing
|
||||
inc_file = included_files[idx + pos]
|
||||
except ValueError:
|
||||
included_files.append(orig_inc_file)
|
||||
inc_file = orig_inc_file
|
||||
|
||||
inc_file.add_host(original_host)
|
||||
try:
|
||||
inc_file.add_host(original_host)
|
||||
except ValueError:
|
||||
# The host already exists for this include, advance forward, this is a new include
|
||||
idx += pos + 1
|
||||
else:
|
||||
break
|
||||
|
||||
return included_files
|
||||
|
||||
Reference in New Issue
Block a user