down votefavorite
|
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.
|
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