Execute python module from ansible?

27 views
Skip to first unread message

John Menke

unread,
Jun 8, 2021, 5:06:13 PM6/8/21
to Ansible Project
in python i can do 
python -m  packagename.modulename 

I am trying this from ansible script and its not finding python

reg...@gmail.com

unread,
Jun 9, 2021, 12:15:38 AM6/9/21
to Ansible Project
Are you using the shell module to send the command line? Perhaps try using the full path to the python interpreter you want to use.
Often '/usr/bin/python' is a link to /usr/bin/python2 or /usr/bin/python3

There may be a more elegant way as well, just a thought though. I'm a bit curious also, I haven't had time, but I have had a couple use case ideas using some python scripts in Ansible.

I did find this post, where it's mentioned to 'cd' first, but personally - I'd just use the full path to python.

/usr/bin/python -m  packagename.modulename   (If it complains there's no 'python' use /usr/bin/python2 or /usr/bin/python3 or create a symlink from /usr/bin/python to your chosen version)

reg...@gmail.com

unread,
Jun 9, 2021, 12:16:24 AM6/9/21
to Ansible Project
Reply all
Reply to author
Forward
0 new messages