
Show HN: Ansible Kernel – Run Ansible Tasks and Plays with Jupyter Notebook - import_awesome
https://github.com/ansible/ansible-jupyter-kernel
======
tejtm
Until there is a meaningful `git diff` for jupyter notebooks I can't see them
being a step in the right direction for anything but transient experiments
(and of course what Jypyter is great at; communication, documentation, low
barriers etc.)

~~~
massaman_yams
This is effectively a solved problem, but it does require some tooling. Pre-
commit hooks can strip things like execution count and/or outputs from the
notebook:
[https://gist.github.com/minrk/6176788](https://gist.github.com/minrk/6176788)

~~~
tejtm
Thanks will give this a try

~~~
massaman_yams
caveat: I haven't tested this particular one, it was just the first thing I
found in a quick search.

This post has more detail on a faster approach using jq:
[http://timstaley.co.uk/posts/making-git-and-jupyter-
notebook...](http://timstaley.co.uk/posts/making-git-and-jupyter-notebooks-
play-nice/)

------
jarpineh
I have been making Jupyter notebook for managing our container environment.
Some work is still only possible through Ansible, so I've been wondering how
to integrate that. Well, I need not wonder no more!

This looks very promising:

* auto completion!

* integrated documentation!

* exporting Ansible YAML!

I didn't yet have change to play with this, so I just note the ways I see
Jupyter can be good fit for Ansible. You can try each step and see it working
before moving to next one. There doesn't seem to be support yet for richer
results view nor Jupyter Widgets, but imagine looking at actual error messages
and result views instead of JSON as text. Getting and setting parameters for
playbooks could be done using external data sources instead of hand-crafting
inventories and config files. You could use same approach as Ara [1] and trace
execution of tasks.

I assume you can run Ansible kernel from JupyterLab instance, so you can do
file management and use terminal right on the machine you're running Ansible
commands. Also, I'd imagine connecting with Jupyter Console (formerly IPython)
to same kernel state as notebook is running with is possible here as well.
This provides Terminal goodness alongside browser's visuals.

[1] Ara:
[http://ara.readthedocs.io/en/latest/](http://ara.readthedocs.io/en/latest/)

~~~
import_awesome
Try it on Binder here:

[https://mybinder.org/v2/gh/ansible/ansible-jupyter-
kernel/ma...](https://mybinder.org/v2/gh/ansible/ansible-jupyter-
kernel/master)

~~~
jarpineh
Hi, and thank you. It works well. Example play books already contain the
basics I'd need for my playbooks.

Could you perhaps elaborate how the kernel directs Ansible?

Also, is there any difference between local and remote Ansible runs?

~~~
import_awesome
Ansible Kernel calls ansible-playbook on a specially constructed playbook.
Ansible Kernel constructs a playbook with a two tasks in it: 1. wait for the
kernel and 2. include tasks from a file that does not exist yet. When you
enter a #task cell we write that included file and then tell the wait task to
proceed. The included file contains the #task cell contents, a wait task, and
another include task. This continues until you stop the kernel, the playbook
dies on an error, or you enter a #play cell. On a #play cell ansible kernel
throws away the old playbook and make a new one with the new arguments. The
exported playbook just contains the content on the page (without the
wait/include tasks) and should work with ansible-playbook normally.

~~~
jarpineh
This does sound like Ansible does not make it easy to control it from pure
Python. It looks an ingenious way to get around it.

I came across this Python wrapper around Ansible yesterday:
[http://suitable.readthedocs.io/en/latest/](http://suitable.readthedocs.io/en/latest/)
Official docs declare themselves deprecated...

Anyway, I'll have to start testing this soon. Thank you so much for making it!

~~~
import_awesome
You're welcome. I hope that you find it useful.

------
hsitz
Reminds me of the "Literate Devops with Emacs" article that has been discussed
on HN before. Orgmode is well suited for this sort of thing:

[https://news.ycombinator.com/item?id=16559004](https://news.ycombinator.com/item?id=16559004)

------
rb808
I really like the idea of notebooks for ops tasks - its a great combination of
code, documentation and step by step execution. I'm surprised it is not more
popular.

------
spydum
I... don’t get the use case for this? What am I missing?

~~~
vinayan3
To me it looks like a REPL for Ansible. If it does let you build each task in
a cell then you could develop the whole playbook interactively and
incrementally. It could reduce the turn around time of having to run a long
playbook and waiting till the latest step you wrote.

~~~
throwaway5752
Doesn't ansible core have ansible console already? This seems very bizarre and
solution in search of a problem. An alexa skill for ansible would be
interesting, but I wouldn't use it, either.

edit: [https://docs.ansible.com/ansible/latest/cli/ansible-
console....](https://docs.ansible.com/ansible/latest/cli/ansible-console.html)
"REPL console for executing Ansible tasks."

~~~
kbumsik
What Jupyter (regardless of its kernel: Ansible, Python etc...) does is just
adding a GUI interface on top of an existing REPL console you mentioned. For
example, you already have a working iPython REPL console, you don't really
need the heavy Jupyter system to run scientific Python codes.

If you prefer to use the REPL consoles directly for your own propose then
Jupyter will add no value on it. However, Jupyter let you save results for
each commands without running them again, and you can add Markdown
documentations. This is useful when you want document your codes (with
results) and share them with others.

Jupyter is merely a productivity tool like an IDE, not a framework. Jupyter
may not be suitable for running production codes anyway.

