ansible / ansible-jupyter-kernel

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

In case of Python 3.6, register variable error occurs. #69

Closed sky-joker closed 6 years ago

sky-joker commented 6 years ago

Describe the bug

When Ansible Kernel 0.8.0 is running in Docker container, the following error occurred.(Ansible Kernel is running on Python3.6) The same error does not occur in python2.

To Reproduce

# docker run -p 8888:8888 -d -it --name jupyter centos:centos7
# docker exec -it jupyter bash
# yum -y install epel-release
# yum -y install python36 python36-devel gcc
# curl https://bootstrap.pypa.io/get-pip.py | python36
# pip3 install jupyter jupyterlab
# pip3 install ansible ansible-kernel ipython
# python36 -m ansible_kernel.install
# jupyter lab --ip=0.0.0.0 --allow-root

Screenshots

bug_to_reproduce_register_variable

register_variable_bug

Desktop (please complete the following information):

Additional context

I fixed the bug as follows.

--- before/kernel.py    2018-09-29 14:31:59.057127090 +0000
+++ after/kernel.py 2018-09-29 14:32:22.212129487 +0000
@@ -432,7 +432,7 @@

             if message_data.get('full_results', None) and self.registered_variable is not None:
                 logger.debug('full_results %s', type(message_data.get('full_results')))
-                self.shell.run_cell("{0} = json.loads('{1}')".format(self.registered_variable,
+                self.shell.run_cell("import json; {0} = json.loads('{1}')".format(self.registered_variable,
                                                                      message_data.get('full_results')))

             if message_data.get('results', None):

fix_to_reproduce_register_variable

thanks.

benthomasson commented 6 years ago

Please make a pull request with those changes. Thanks for the issue report!