New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Automatically detect interpreters (alternate approach) #42783

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
4 participants
@agaffney
Contributor

agaffney commented Jul 14, 2018

SUMMARY

This commit adds an action plugin called 'gather_interpreters' and runs it automatically as part of play fact gathering. This plugin uses 'which' (on platforms where it's supported) to find the full path of a list of possible interpreter names and sets the appropriate 'ansible_x_interpreter' var.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

interpreter path

ANSIBLE VERSION
ansible 2.7.0.dev0 (gather_interpreters 1a60f99df2) last updated 2018/07/14 10:49:22 (GMT -500)
ADDITIONAL INFORMATION

N/A

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch 7 times, most recently Jul 14, 2018

@ansible ansible deleted a comment from ansibot Jul 14, 2018

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch 3 times, most recently Jul 14, 2018

@ansible ansible deleted a comment from ansibot Jul 14, 2018

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch Jul 14, 2018

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch 4 times, most recently Jul 14, 2018

@ansibot ansibot added the test label Jul 15, 2018

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch Jul 15, 2018

@sivel

This comment has been minimized.

Member

sivel commented Jul 15, 2018

Overall this is the approach that I was discussing at some point. The biggest difference is that I think instead of trying to use which I was recommending just trying to exec the python versions with -V or something. Just figured I'd mention it.

And instead of an action I was using a new block, calling the raw module in a block/rescue/finally manner.

Anyway, just ideas.

@agaffney

This comment has been minimized.

Contributor

agaffney commented Jul 15, 2018

This implementation can be used for interpreters other than python by adding them to the list, and trying to parse version numbers from a bunch of arbitrary interpreters doesn't sound pleasant.

I opted for an action plugin so that the action could be performed again arbitrarily, like is currently possible for setup.

@sivel

This comment has been minimized.

Member

sivel commented Jul 15, 2018

trying to parse version numbers from a bunch of arbitrary interpreters doesn't sound pleasant

Oh, I had no intention of actually parsing the response. I was just using -V as it would cause the interpreter to not open, just print the version and exit.

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch Jul 16, 2018

@jborean93 jborean93 removed the needs_triage label Jul 19, 2018

lib/ansible/plugins/shell/sh.py Outdated
@@ -40,6 +40,12 @@ class ShellModule(ShellBase):
_SHELL_GROUP_LEFT = '('
_SHELL_GROUP_RIGHT = ')'
def find_binary(self, bins):
if not type(bins) == list:

This comment has been minimized.

@sivel

sivel Jul 22, 2018

Member

This should be an isinstance check

This comment has been minimized.

@agaffney

agaffney Jul 23, 2018

Contributor

Fixed

Automatically detect interpreters
This commit adds an action plugin called 'gather_interpreters' and runs
it automatically as part of play fact gathering. This plugin uses
'which' (on platforms where it's supported) to find the full path of a
list of possible interpreter names and sets the appropriate
'ansible_x_interpreter' var.

@agaffney agaffney force-pushed the agaffney:gather_interpreters branch to 373dab2 Jul 23, 2018

@agaffney

This comment has been minimized.

Contributor

agaffney commented Jul 23, 2018

I've realized this this implementation implicitly relies on facts being injected as vars, which means that it may be necessary to inject the vars into VarsManager directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment