ansible / ansible-jupyter-kernel

Jupyter Notebook Kernel for running Ansible Tasks and Playbooks
Other
534 stars 62 forks source link

Getting the output of tasks on multiple hosts #68

Closed montaropdf closed 5 years ago

montaropdf commented 6 years ago

Describe the bug Tasks runs for all hosts of the group specified in directive hosts, but any python cells afterward only get the result of the execution on the last host to finish its execution for the task.

To Reproduce Steps to reproduce the behavior:

  1. Create a notebook with the ansible kernel
  2. Fill the first cell with an ansible inventory listing more then 1 host
  3. In the second cell initiate an ansible playbook
  4. In the third cell define a task and add the register directive to retrieve the output from the execution
  5. In the fourth cell create a python block that will print the content of the variable specified in the register directive

Expected behavior Provide a way for python code to be executed each time a task is executed for a host or ensure that variables in register directives are lists that will accumulate the results of each task execution.

Desktop (please complete the following information):

Server (please complete the following information):

Additional context Add any other context about the problem here.

benthomasson commented 6 years ago

Thanks for submitting this issue. I am considering different ways that this could work. I could create a dictionary in the python environment with the results of all the hosts keyed by host name. Would that work for you?

montaropdf commented 6 years ago

Yes, definitively.

Another solution, thou, could be to treat "#python" as an ansible handler that can be notified. That could avoid having very huge amount of data in memory for, potentially, a long time. Do you think that could be possible?

Anyway implement what is the easiest for you.

benthomasson commented 6 years ago

The memory use is a good point. I'll think about this a bit more. Ansible already holds too much in memory. I'll try not to make that worse.