From 928d51606eb3943bd1cdcbfa0462719a3a72ccff Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Apr 19 2018 06:54:07 +0000 Subject: check docker container to find out which python version to use --- diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker index f75e6c6..40006d8 100755 --- a/inventory/standard-inventory-docker +++ b/inventory/standard-inventory-docker @@ -132,11 +132,31 @@ def inv_host(image, docker_extra_args): with open(cidfile, "r") as f: name = f.read().strip() + # Need to figure out what python interpreter to use + interpreters = ["/usr/bin/python2", "/usr/bin/python3"] + for interpreter in interpreters: + check_file = ["/usr/bin/docker", "exec", "--user=root", name, "/usr/bin/ls", 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 + + python2_deps = ["python2-dnf", "libselinux-python"] + python3_deps = ["python3-dnf", "python3-libselinux"] + # Now install the necessary stuff in the container :S install = [ - "/usr/bin/docker", "exec", "--user=root", name, "/usr/bin/yum", "-y", "install", - "python2", "python2-dnf", "libselinux-python" + "/usr/bin/docker", "exec", "--user=root", name, "/usr/bin/yum", "-y", "install" ] + if ansible_python_interpreter == "/usr/bin/python2": + install.extend(python2_deps) + if ansible_python_interpreter == "/usr/bin/python3": + install.extend(python3_deps) try: subprocess.check_call(install, stdout=sys.stderr.fileno()) except subprocess.CalledProcessError: @@ -151,6 +171,7 @@ def inv_host(image, docker_extra_args): # The variables variables = { "ansible_connection": "docker", + "ansible_python_interpreter": ansible_python_interpreter } # Process of our parent diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index 3643251..10cfd3b 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -241,7 +241,7 @@ def inv_host(image): # Need to figure out what python interpreter to use interpreters = ["/usr/bin/python2", "/usr/bin/python3"] for interpreter in interpreters: - check_file = [ + check_file = [ "/usr/bin/ansible", "--inventory", inventory,