mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-22 15:04:33 -07:00
Warn when cond is used on meta tasks that don't support them (#41126)
This commit is contained in:
parent
828e33f419
commit
5f7ffd39dc
1 changed files with 11 additions and 4 deletions
|
@ -938,16 +938,15 @@ class StrategyBase:
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def _cond_not_supported_warn(self, task_name):
|
||||||
|
display.warning("%s task does not support when conditional" % task_name)
|
||||||
|
|
||||||
def _execute_meta(self, task, play_context, iterator, target_host):
|
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
|
||||||
meta_action = task.args.get('_raw_params')
|
meta_action = task.args.get('_raw_params')
|
||||||
|
|
||||||
# FIXME(s):
|
|
||||||
# * raise an error or show a warning when a conditional is used
|
|
||||||
# on a meta task that doesn't support them
|
|
||||||
|
|
||||||
def _evaluate_conditional(h):
|
def _evaluate_conditional(h):
|
||||||
all_vars = self._variable_manager.get_vars(play=iterator._play, host=h, task=task)
|
all_vars = self._variable_manager.get_vars(play=iterator._play, host=h, task=task)
|
||||||
templar = Templar(loader=self._loader, variables=all_vars)
|
templar = Templar(loader=self._loader, variables=all_vars)
|
||||||
|
@ -957,11 +956,17 @@ class StrategyBase:
|
||||||
msg = ''
|
msg = ''
|
||||||
if meta_action == 'noop':
|
if meta_action == 'noop':
|
||||||
# FIXME: issue a callback for the noop here?
|
# FIXME: issue a callback for the noop here?
|
||||||
|
if task.when:
|
||||||
|
self._cond_not_supported_warn(meta_action)
|
||||||
msg = "noop"
|
msg = "noop"
|
||||||
elif meta_action == 'flush_handlers':
|
elif meta_action == 'flush_handlers':
|
||||||
|
if task.when:
|
||||||
|
self._cond_not_supported_warn(meta_action)
|
||||||
self.run_handlers(iterator, play_context)
|
self.run_handlers(iterator, play_context)
|
||||||
msg = "ran handlers"
|
msg = "ran handlers"
|
||||||
elif meta_action == 'refresh_inventory' or self.flush_cache:
|
elif meta_action == 'refresh_inventory' or self.flush_cache:
|
||||||
|
if task.when:
|
||||||
|
self._cond_not_supported_warn(meta_action)
|
||||||
self._inventory.refresh_inventory()
|
self._inventory.refresh_inventory()
|
||||||
msg = "inventory successfully refreshed"
|
msg = "inventory successfully refreshed"
|
||||||
elif meta_action == 'clear_facts':
|
elif meta_action == 'clear_facts':
|
||||||
|
@ -988,6 +993,8 @@ class StrategyBase:
|
||||||
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
|
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
|
||||||
msg = "ending play"
|
msg = "ending play"
|
||||||
elif meta_action == 'reset_connection':
|
elif meta_action == 'reset_connection':
|
||||||
|
if task.when:
|
||||||
|
self._cond_not_supported_warn(meta_action)
|
||||||
if target_host in self._active_connections:
|
if target_host in self._active_connections:
|
||||||
connection = Connection(self._active_connections[target_host])
|
connection = Connection(self._active_connections[target_host])
|
||||||
del self._active_connections[target_host]
|
del self._active_connections[target_host]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue