Access ansible list in python script.

Hi,

I’m calling a python script by passing an ansible list as an argument.

command: “python /home/vagrant/setup/configs/update_installed_app.py [‘django-allauth’, ‘test’]”

But when i print this list in my python script its printing with misplaced quotes, so i couldnt process it with python.

[‘[django-allauth,’, ‘test]’]

“rc”: 0,
“start”: “2015-12-10 06:22:12.327672”,
“stderr”: “”,
“stdout”: “[‘[django-allauth,’, ‘test]’]”,
“stdout_lines”: [
“[‘[django-allauth,’, ‘test]’]”

Could someone please help me out here.

Instead of passing a python list, can you pass a json string? Then, inside the py script, just use json.loads().

Hi Mike,

Thank you for your response.

I resolved this by following steps.

  1. I quoted the arguments passed with the command like python /home/vagrant/setup/configs/update_installed_app.py “[‘django-allauth’, ‘test’]
  2. In python script I can access it as a string. Then using python ‘ast’ module i’m converted it into python list.