Access ansible list in python script.

53 views
Skip to first unread message

anoop....@tarams.com

unread,
Dec 10, 2015, 1:30:49 AM12/10/15
to Ansible Project
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.

Mike Biancaniello

unread,
Dec 10, 2015, 11:08:54 AM12/10/15
to Ansible Project
Instead of passing a python list, can you pass a json string? Then, inside the py script, just use json.loads().

anoop....@tarams.com

unread,
Dec 10, 2015, 12:53:55 PM12/10/15
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages