From 013de4f881769cfa967bad60e81833a1c4d9c45e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 26 Jun 2023 15:41:44 -0400 Subject: [PATCH] Adapt to ansible python runtime Unfortunately, python being python, ansible may elect to install under a different python runtime than confluent. In such a case, hope that the ansible python can work. Remove eventlet as a hard requirement, as that is unlikely to be in ansible python. This leaves msgpack, which is unavoidable, for now. But if it's in ansible python, it's fine. --- confluent_server/confluent/runansible.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/runansible.py b/confluent_server/confluent/runansible.py index 832fc788..9ba70938 100644 --- a/confluent_server/confluent/runansible.py +++ b/confluent_server/confluent/runansible.py @@ -17,16 +17,17 @@ try: import confluent.sshutil as sshutil + import eventlet + import eventlet.green.subprocess as subprocess except ImportError: pass -import eventlet -import eventlet.green.subprocess as subprocess import json import msgpack import os import struct import sys +anspypath = None running_status = {} class PlayRunner(object): def __init__(self, playfiles, nodes): @@ -73,11 +74,22 @@ class PlayRunner(object): } def _really_run_playbooks(self): + global anspypath + mypath = anspypath + if not mypath: + ansloc = shutil.which('ansible') + if ansloc: + with open(onsloc, 'r') as onsop: + shebang = onsop.readline() + anspypath = shebang.strip().replace('#!', '') + mypath = anspypath + if not mypath: + mypath = sys.executable with open(os.devnull, 'w+') as devnull: targnodes = ','.join(self.nodes) for playfilename in self.playfiles: worker = subprocess.Popen( - [sys.executable, __file__, targnodes, playfilename], + [mypath, __file__, targnodes, playfilename], stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, self.stderr = worker.communicate()