fix regression in Darwin 19 (OSX 10.15+) ansible python interpreter detection

This commit is contained in:
Steven Robertson 2020-10-24 17:28:26 -07:00
parent a561a8bad2
commit 518324c371
2 changed files with 12 additions and 2 deletions

View File

@ -42,6 +42,7 @@ import heapq
import inspect import inspect
import logging import logging
import os import os
import platform
import re import re
import signal import signal
import socket import socket
@ -1434,7 +1435,10 @@ class Connection(object):
os.close(r) os.close(r)
os.close(W) os.close(W)
os.close(w) os.close(w)
if sys.platform == 'darwin' and sys.executable == '/usr/bin/python': # this doesn't apply anymore to Mac OSX 10.15+ (Darwin 19+), new interpreter looks like this:
# /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
if sys.platform == 'darwin' and sys.executable == '/usr/bin/python' and \
int(platform.release()[:2]) < 19:
sys.executable += sys.version[:3] sys.executable += sys.version[:3]
os.environ['ARGV0']=sys.executable os.environ['ARGV0']=sys.executable
os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)') os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)')

View File

@ -9,6 +9,7 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
import platform
import sys import sys
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -23,7 +24,12 @@ def main():
result['ansible_facts'] = module.params['facts'] result['ansible_facts'] = module.params['facts']
# revert the Mitogen OSX tweak since discover_interpreter() doesn't return this info # revert the Mitogen OSX tweak since discover_interpreter() doesn't return this info
if sys.platform == 'darwin' and sys.executable != '/usr/bin/python': if sys.platform == 'darwin' and sys.executable != '/usr/bin/python':
sys.executable = sys.executable[:-3] if int(platform.release()[:2]) < 19:
sys.executable = sys.executable[:-3]
else:
# only for tests to check version of running interpreter -- Mac 10.15+ changed python2
# so it looks like it's /usr/bin/python but actually it's /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
sys.executable = "/usr/bin/python"
result['running_python_interpreter'] = sys.executable result['running_python_interpreter'] = sys.executable
module.exit_json(**result) module.exit_json(**result)