/usr/bin/env on Python Azure dynamic inventory

371 views
Skip to first unread message

André Cruz

unread,
May 23, 2016, 2:06:52 PM5/23/16
to Ansible Project
Hello.

I submitted a PR https://github.com/ansible/ansible/pull/15965 to use /usr/bin/env instead of referring to a specific Python executable in the Azure dynamic inventory. This was rejected on the basis that all ansible modules had to refer to "/usr/bin/python". Does this make sense? This script is to be run locally and if ansible is on a virtualenv the Python executable will not be the correct one.

I understand this rule when applied to modules that are run on remote machines, but in this case I think it makes sense not to hardcode the Python interpreter.

Best regards,
André

Brian Coca

unread,
May 23, 2016, 2:09:08 PM5/23/16
to ansible...@googlegroups.com
It does not NEED to run locally, many will execute on a delegated host that has access. Not all environments have direct access to the API they need to use.

The 'local' execution might be the most common use of cloud modules, but even then `env python` might not be the correct python, for localhost ansible replaces with the 'currently executing python' (sys.executable) which should be the correct one.


----------
Brian Coca

André Cruz

unread,
May 24, 2016, 5:42:04 AM5/24/16
to Ansible Project
On Monday, May 23, 2016 at 7:09:08 PM UTC+1, Brian Coca wrote:
The 'local' execution might be the most common use of cloud modules, but even then `env python` might not be the correct python, for localhost ansible replaces with the 'currently executing python' (sys.executable) which should be the correct one.

Are you sure it does that?

I even tried with the "devel" branch and it did not do that:

$ ansible -i contrib/inventory/azure_rm.py azure
ERROR! Inventory script (contrib/inventory/azure_rm.py) had an execution error: The Azure python sdk is not installed (try 'pip install azure') - No module named msrestazure.azure_exceptions

contrib/inventory/azure_rm.py:22: Error parsing host definition ''''': No closing quotation

But I do have it installed in this environment:

(ansible)[andre@Giedi ~/work/vc/ansible]$ python -c "import msrestazure.azure_exceptions"
(ansible)[andre@Giedi ~/work/vc/ansible]$

If I change the /usr/bin/python call to use the "env" in azure_rm.py everything works.

André

Brian Coca

unread,
May 24, 2016, 10:04:15 AM5/24/16
to ansible...@googlegroups.com
Unless you specifically override this, here is the code:



----------
Brian Coca

André Cruz

unread,
May 24, 2016, 10:08:22 AM5/24/16
to Ansible Project
How could I have overridden this? I didn't pass any flags in the command line and the only env vars set are the ones 'hacking/env-setup' put there.

André

Brian Coca

unread,
May 24, 2016, 11:18:10 AM5/24/16
to ansible...@googlegroups.com
did you define localhost in inventory?


----------
Brian Coca

André Cruz

unread,
May 24, 2016, 11:20:02 AM5/24/16
to Ansible Project
This is the dynamic inventory script for Azure (azure_rm.py). The problem is running the dynamic inventory script itself.

André

Matt Martz

unread,
May 24, 2016, 11:22:52 AM5/24/16
to ansible...@googlegroups.com
So, just as an FYI here, I had mistakenly closed the issue yesterday, as I had thought it was for a module and not an inventory.  The issue was re-opened yesterday as well.

On Tue, May 24, 2016 at 10:20 AM, André Cruz <andre...@gmail.com> wrote:
This is the dynamic inventory script for Azure (azure_rm.py). The problem is running the dynamic inventory script itself.

André

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/63892032-87d2-4a86-811a-3afa1296a0ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
May 24, 2016, 11:28:27 AM5/24/16
to ansible...@googlegroups.com
Ah, same mistake here, i thought this was about module execution.


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages