# Ansible python scripts and registers issue

**URL:** <https://forum.ansible.com/t/ansible-python-scripts-and-registers-issue/25269>\
**Category:** Ansible Project\
**Created:** [August 16, 2017, 4:42pm UTC](https://forum.ansible.com/t/ansible-python-scripts-and-registers-issue/25269 "2017-08-16T16:42:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Monte](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@Tom\_Monte](https://forum.ansible.com/u/Tom_Monte)\
**Post date:** [August 16, 2017, 4:42pm UTC](https://forum.ansible.com/t/ansible-python-scripts-and-registers-issue/25269/1 "2017-08-16T16:42:03Z")

</div>

> down vote[favorite](https://serverfault.com/questions/868770/ansible-pass-dictionary-from-python-script#)  
>   
>   
> |   
>   
>   
>   
> I am running a Ansible script that calls a python script, which manipulates some data and turns it into a dictionary. I want to redirect the python dictionary to a register and then use it replace sections of a json file. My script runs without any messages. I can run the python script by itself and it prints out the dictionary.  
>   
>   
>   
> What am I doing wrong? Is this the best way to do this? Is it better to use shell, command or script to call python scripts?  
>   
>   
>   
> `<br>pyscript.py<br>pydict[pykey] = pyvalue<br>print (pydict)<br><br><br>ansiblescript.yml<br>---<br>- hosts: 10.215.237.238<br> tasks: <br><br> - name : Gather info<br> shell: '/usr/bin/python /home/devoper/scripts/pyscript.py'<br> register: pydict<br><br><br> - name: Insert Info<br> replace:<br> destfile: /home/devoper/scripts/template.json<br> regexp: "KEY1"<br> replace: "{{ pydict.pykey }}"<br> backup: yes<br><br>`  
>   
>   
>   
> Thank you for your time.  
>   
>   
>   
> |

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 16, 2017, 4:43pm UTC](https://forum.ansible.com/t/ansible-python-scripts-and-registers-issue/25269/2 "2017-08-16T16:43:54Z")

</div>

`pydict` is going to come with a `stdout` key, which will be a string of your dictionary. I don’t know how you are printing the dict, but you should probably turn it into JSON and then print it.

Then later you can use:

(pydict.stdout|from\_json).pykey
