CORD-706: Bug fixes involving vSG synchronizer

Change-Id: I9f20069a53757f5da886aa5ed2ee2d4a31aa24fc
diff --git a/xos/synchronizers/base/ansible_helper.py b/xos/synchronizers/base/ansible_helper.py
index 61520df..9061fd9 100644
--- a/xos/synchronizers/base/ansible_helper.py
+++ b/xos/synchronizers/base/ansible_helper.py
@@ -11,7 +11,6 @@
 import subprocess
 from xos.config import Config, XOS_DIR
 from xos.logger import observer_logger as logger
-from ansible_runner import *
 
 step_dir = Config().observer_steps_dir
 sys_dir = Config().observer_sys_dir
@@ -56,19 +55,20 @@
     f.write(buffer)
     f.flush()
 
-    # This is messy -- there's no way to specify ansible config file from
-    # the command line, but we can specify it using the environment.
-    env = os.environ.copy()
     if ansible_config:
-       env["ANSIBLE_CONFIG"] = ansible_config
+       os.environ["ANSIBLE_CONFIG"] = ansible_config
     if ansible_hosts:
-       env["ANSIBLE_HOSTS"] = ansible_hosts
+       os.environ["ANSIBLE_HOSTS"] = ansible_hosts
+
+    # This import needs to be here, otherwise ANSIBLE_CONFIG does not take effect
+    from ansible_runner import Runner
+
 
     # Dropped support for observer_pretend - to be redone
     runner = Runner(
         playbook=fqp,
-        run_data=opts)
-        
+        run_data=opts,
+        host_file=ansible_hosts)
 
     stats,aresults = runner.run()
 
diff --git a/xos/synchronizers/base/ansible_runner.py b/xos/synchronizers/base/ansible_runner.py
index 8089b43..d2d9f15 100644
--- a/xos/synchronizers/base/ansible_runner.py
+++ b/xos/synchronizers/base/ansible_runner.py
@@ -2,6 +2,7 @@
 
 import os
 import sys
+import pdb
 
 from tempfile import NamedTemporaryFile
 from ansible.inventory import Inventory
@@ -10,6 +11,7 @@
 from ansible.executor import playbook_executor
 from ansible.utils.display import Display
 from ansible.plugins.callback import CallbackBase
+from xos.logger import observer_logger as logger
 
 
 class ResultCallback(CallbackBase):
@@ -18,6 +20,7 @@
         self.results = []
 
     def v2_runner_on_ok(self, result, **kwargs):
+        logger.info("OK: %s"%str(result._task))
         self.results.append(result)
     
     def v2_runner_on_failed(self, result, **kwargs):
@@ -85,10 +88,9 @@
 
 class Runner(object):
 
-    def __init__(self, playbook, run_data, private_key_file=None, verbosity=0):
+    def __init__(self, playbook, run_data, private_key_file=None, verbosity=0, host_file=None):
 
         self.run_data = run_data
-
         self.options = Options()
         self.options.output_file = playbook + '.result'
         self.options.private_key_file = private_key_file
@@ -118,10 +120,14 @@
         
         # All the variables from all the various places
         self.variable_manager = VariableManager()
-        self.variable_manager.extra_vars = self.run_data
+        self.variable_manager.extra_vars = {} # self.run_data
 
         # Set inventory, using most of above objects
-        self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager)
+        if (host_file):
+            self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager, host_list = host_file)
+        else:
+            self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager)
+
         self.variable_manager.set_inventory(self.inventory)