#287 Search for ansible binary rather than hardcoded.
Merged 5 years ago by astepano. Opened 5 years ago by astepano.

@@ -17,6 +17,7 @@ 

  import tempfile

  import time

  import distutils.util

+ import functools

  

  import yaml

  
@@ -121,6 +122,15 @@ 

      unicode = str

  

  

+ def which(executable, default=None):

+     for path in os.environ['PATH'].split(os.pathsep):

+         path = path.strip('"')

+         fpath = os.path.join(path, executable)

+         if os.path.isfile(fpath) and os.access(fpath, os.X_OK):

+             return fpath

+     return default

+ 

+ 

  def main(argv):

      parser = argparse.ArgumentParser(description="Inventory for a QCow2 test image")

      parser.add_argument("--list", action="store_true", help="Verbose output")
@@ -138,6 +148,13 @@ 

      fhandler.setFormatter(logFormatter)

      logger.addHandler(fhandler)

      logger.info("Start provisioner.")

+     ansibles = ['ansible', 'ansible-3', None]

+     global ansible_bin

+     ansible_bin = functools.reduce(which, ansibles)

+     if not ansible_bin:

+         logger.error("Fail to find ansible.")

+         sys.exit(1)

+     logger.info("Path to ansible: %s", ansible_bin)

      if opts.host:

          data = inv_host(opts.host)

      else:
@@ -412,7 +429,7 @@ 

  

              # Wait for ssh to come up

              ping = [

-                 "/usr/bin/ansible",

+                 ansible_bin,

                  "--inventory",

                  inventory,

                  "localhost",
@@ -453,7 +470,7 @@ 

          interpreters = ["/usr/bin/python3", "/usr/bin/python2", "/usr/libexec/platform-python"]

          for interpreter in interpreters:

              check_file = [

-                 "/usr/bin/ansible",

+                 ansible_bin,

                  "--inventory",

                  inventory,

                  "localhost",

Commit 94034b7 fixes this pull-request

Pull-Request has been merged by astepano

5 years ago

Pull-Request has been merged by astepano

5 years ago