From 6da00a2ef212b6e89f6b91931a6f7dac067bb88a Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Apr 17 2018 14:24:36 +0000 Subject: check qcow2 image to find out which python version to use --- diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index 740c304..3643251 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -238,6 +238,34 @@ def inv_host(image): child = os.fork() if child: + # Need to figure out what python interpreter to use + interpreters = ["/usr/bin/python2", "/usr/bin/python3"] + for interpreter in interpreters: + check_file = [ + "/usr/bin/ansible", + "--inventory", + inventory, + "localhost", + "--module-name", + "raw", + "--args", + "ls %s" % interpreter + ] + try: + subprocess.check_call(check_file, stdout=null, stderr=null) + ansible_python_interpreter = interpreter + break + except subprocess.CalledProcessError: + pass + else: + sys.stderr.write("ERROR: Could not set ansible_python_interpreter") + return None + variables["ansible_python_interpreter"] = ansible_python_interpreter + # Update inventory file + args = " ".join(["{0}='{1}'".format(*item) for item in variables.items()]) + inventory = os.path.join(directory, "inventory") + with open(inventory, "w") as f: + f.write("[subjects]\nlocalhost {0}\n".format(args)) return variables # Daemonize and watch the processes