Add shorthand debugger method to recreate the task from the original ds (#46987)

* Add shorthand debugger method to recreate the task from the original ds, and re-template. Fixes #46321

* Fix rst header

* Indicate update_task was added in 2.8
This commit is contained in:
Matt Martz 2018-10-25 16:35:59 -05:00 committed by GitHub
parent 6c2e4c1ca8
commit f7ba63e047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -235,6 +235,7 @@ Let's use the same playbook above, but fix ``task_vars`` instead of args::
[192.0.2.10] TASK: install package (debug)> task_vars['pkg_name'] = 'bash'
[192.0.2.10] TASK: install package (debug)> p task_vars['pkg_name']
'bash'
[192.0.2.10] TASK: install package (debug)> update_task
[192.0.2.10] TASK: install package (debug)> redo
Then the task runs again with new ``task_vars``.
@ -242,6 +243,17 @@ Then the task runs again with new ``task_vars``.
.. note::
In 2.5 this was updated from ``vars`` to ``task_vars`` to not conflict with the ``vars()`` python function.
.. _update_task_command:
u(pdate_task)
`````````````
.. versionadded:: 2.8
This command re-creates the task from the original task data structure, and templates with updated ``task_vars``
See the above documentation for :ref:`update_vars_command` for an example of use.
.. _redo_command:
r(edo)

View file

@ -1200,6 +1200,16 @@ class Debugger(cmd.Cmd):
do_r = do_redo
def do_update_task(self, args):
"""Recreate the task from ``task._ds``, and template with updated ``task_vars``"""
templar = Templar(None, shared_loader_obj=None, variables=self.scope['task_vars'])
task = self.scope['task']
task = task.load_data(task._ds)
task.post_validate(templar)
self.scope['task'] = task
do_u = do_update_task
def evaluate(self, args):
try:
return eval(args, globals(), self.scope)