Execute python module from ansible?

in python i can do
python -m packagename.modulename

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

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)

Ehh - this post - I meant to link above :slight_smile:

https://serverfault.com/questions/769898/running-python-script-on-anisble