mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
removed bad iteration from execute meta (#19958)
* removed bad iteration from execute meta most of the tasks should not be iterated over, others needed to include unreachable hosts fixes #19673 * corrected host var
This commit is contained in:
parent
e9038d8dc1
commit
08ef0aee25
2 changed files with 42 additions and 42 deletions
|
@ -854,7 +854,7 @@ class StrategyBase:
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _execute_meta(self, task, play_context, iterator, target_host=None):
|
def _execute_meta(self, task, play_context, iterator, target_host):
|
||||||
|
|
||||||
# meta tasks store their args in the _raw_params field of args,
|
# meta tasks store their args in the _raw_params field of args,
|
||||||
# since they do not use k=v pairs, so get that
|
# since they do not use k=v pairs, so get that
|
||||||
|
@ -865,52 +865,52 @@ class StrategyBase:
|
||||||
# on a meta task that doesn't support them
|
# on a meta task that doesn't support them
|
||||||
|
|
||||||
def _evaluate_conditional(h):
|
def _evaluate_conditional(h):
|
||||||
all_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task)
|
all_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=h, task=task)
|
||||||
templar = Templar(loader=self._loader, variables=all_vars)
|
templar = Templar(loader=self._loader, variables=all_vars)
|
||||||
return task.evaluate_conditional(templar, all_vars)
|
return task.evaluate_conditional(templar, all_vars)
|
||||||
|
|
||||||
if target_host:
|
skipped = False
|
||||||
host_list = [target_host]
|
msg = ''
|
||||||
else:
|
|
||||||
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for host in host_list:
|
|
||||||
result = None
|
|
||||||
if meta_action == 'noop':
|
if meta_action == 'noop':
|
||||||
# FIXME: issue a callback for the noop here?
|
# FIXME: issue a callback for the noop here?
|
||||||
result = TaskResult(host, task, dict(changed=False, msg="noop"))
|
msg="noop"
|
||||||
elif meta_action == 'flush_handlers':
|
elif meta_action == 'flush_handlers':
|
||||||
self.run_handlers(iterator, play_context)
|
self.run_handlers(iterator, play_context)
|
||||||
|
msg = "ran handlers"
|
||||||
elif meta_action == 'refresh_inventory':
|
elif meta_action == 'refresh_inventory':
|
||||||
self._inventory.refresh_inventory()
|
self._inventory.refresh_inventory()
|
||||||
result = TaskResult(host, task, dict(changed=False, msg="inventory successfully refreshed"))
|
msg = "inventory successfully refreshed"
|
||||||
elif meta_action == 'clear_facts':
|
elif meta_action == 'clear_facts':
|
||||||
if _evaluate_conditional(host):
|
if _evaluate_conditional(target_host):
|
||||||
self._variable_manager.clear_facts(target_host)
|
for host in self._inventory.get_hosts(iterator._play.hosts):
|
||||||
result = TaskResult(host, task, dict(changed=True, msg="inventory successfully refreshed"))
|
self._variable_manager.clear_facts(host)
|
||||||
|
msg = "facts cleared"
|
||||||
else:
|
else:
|
||||||
result = TaskResult(host, task, dict(changed=False, skipped=True))
|
skipped = True
|
||||||
elif meta_action == 'clear_host_errors':
|
elif meta_action == 'clear_host_errors':
|
||||||
if _evaluate_conditional(host):
|
if _evaluate_conditional(target_host):
|
||||||
|
for host in self._inventory.get_hosts(iterator._play.hosts):
|
||||||
self._tqm._failed_hosts.pop(host.name, False)
|
self._tqm._failed_hosts.pop(host.name, False)
|
||||||
self._tqm._unreachable_hosts.pop(host.name, False)
|
self._tqm._unreachable_hosts.pop(host.name, False)
|
||||||
iterator._host_states[host.name].fail_state = iterator.FAILED_NONE
|
iterator._host_states[host.name].fail_state = iterator.FAILED_NONE
|
||||||
result = TaskResult(host, task, dict(changed=True, msg="successfully cleared host errors"))
|
msg="cleared host errors"
|
||||||
else:
|
else:
|
||||||
result = TaskResult(host, task, dict(changed=False, skipped=True))
|
skipped = True
|
||||||
elif meta_action == 'end_play':
|
elif meta_action == 'end_play':
|
||||||
if _evaluate_conditional(host):
|
if _evaluate_conditional(target_host):
|
||||||
|
for host in self._inventory.get_hosts(iterator._play.hosts):
|
||||||
|
if not host.name in self._tqm._unreachable_hosts:
|
||||||
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
|
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
|
||||||
result = TaskResult(host, task, dict(changed=True, msg="ending play"))
|
msg="ending play"
|
||||||
else:
|
|
||||||
result = TaskResult(host, task, dict(changed=False, skipped=True))
|
|
||||||
#elif meta_action == 'reset_connection':
|
#elif meta_action == 'reset_connection':
|
||||||
# connection_info.connection.close()
|
# connection_info.connection.close()
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("invalid meta action requested: %s" % meta_action, obj=task._ds)
|
raise AnsibleError("invalid meta action requested: %s" % meta_action, obj=task._ds)
|
||||||
|
|
||||||
if result is not None:
|
result = { 'msg': msg }
|
||||||
results.append(result)
|
if skipped:
|
||||||
|
result['skipped'] = True
|
||||||
|
else:
|
||||||
|
result['changed'] = False
|
||||||
|
|
||||||
return results
|
return [TaskResult(target_host, task, result)]
|
||||||
|
|
|
@ -218,7 +218,7 @@ class StrategyModule(StrategyBase):
|
||||||
if task.action == 'meta':
|
if task.action == 'meta':
|
||||||
# for the linear strategy, we run meta tasks just once and for
|
# for the linear strategy, we run meta tasks just once and for
|
||||||
# all hosts currently being iterated over rather than one host
|
# all hosts currently being iterated over rather than one host
|
||||||
results.extend(self._execute_meta(task, play_context, iterator))
|
results.extend(self._execute_meta(task, play_context, iterator, host))
|
||||||
if task.args.get('_raw_params', None) != 'noop':
|
if task.args.get('_raw_params', None) != 'noop':
|
||||||
run_once = True
|
run_once = True
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue