Step to hook into Ansible
authorSapan Bhatia <gwsapan@gmail.com>
Tue, 1 Apr 2014 12:43:13 +0000 (08:43 -0400)
committerSapan Bhatia <gwsapan@gmail.com>
Tue, 1 Apr 2014 12:43:13 +0000 (08:43 -0400)
source/BootManager.py
source/steps/AnsibleHook.py [new file with mode: 0644]

index 68c5052..32d7ba8 100755 (executable)
@@ -277,6 +277,7 @@ class BootManager:
             self.VARS['STATE_CHANGE_NOTIFY']= 1
             self.VARS['STATE_CHANGE_NOTIFY_MESSAGE']= \
                  notify_messages.MSG_INSTALL_FINISHED
             self.VARS['STATE_CHANGE_NOTIFY']= 1
             self.VARS['STATE_CHANGE_NOTIFY_MESSAGE']= \
                  notify_messages.MSG_INSTALL_FINISHED
+            AnsibleHook.Run( self.VARS, self.LOG )
             UpdateBootStateWithPLC.Run( self.VARS, self.LOG )
             _bootRun()
             
             UpdateBootStateWithPLC.Run( self.VARS, self.LOG )
             _bootRun()
             
@@ -289,6 +290,8 @@ class BootManager:
             if not ConfirmInstallWithUser.Run( self.VARS, self.LOG ):
                 return 0
             self.VARS['BOOT_STATE']= 'reinstall'
             if not ConfirmInstallWithUser.Run( self.VARS, self.LOG ):
                 return 0
             self.VARS['BOOT_STATE']= 'reinstall'
+
+            AnsibleHook.Run( self.VARS, self.LOG )
             _reinstallRun()
 
         def _debugRun(state='failboot'):
             _reinstallRun()
 
         def _debugRun(state='failboot'):
diff --git a/source/steps/AnsibleHook.py b/source/steps/AnsibleHook.py
new file mode 100644 (file)
index 0000000..5275e72
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+#
+
+import os
+
+from Exceptions import *
+import utils
+import systeminfo
+
+def run_ansible(ansible_path, ansible_hash, playbook_name, log):
+    try:
+        if (ansible_hash):
+            hash_arg = '-U %s'%ansible_hash
+        else:
+            hash_arg = ''
+        utils.sysexec_noerr('ansible-pull -i hosts %s %s %s' % (ansible_path, hash_arg, playbook_name), log )
+    except:
+        pass
+
+
+def Run( vars, log ):
+    log.write( "\n\nStep: Running Ansible Hook\n" )
+    # make sure we have the variables we need
+    try:
+        ansible_path = vars["ANSIBLE_PATH"]
+        run_level = vars["RUN_LEVEL"]
+        try:
+            ansible_hash = vars["ANSIBLE_HASH"]
+        except KeyError:
+            ansible_hash = None
+
+        if (ansible_path):
+            run_ansible(ansible_path, ansible_hash, "%s.yml"%run_level, log)
+    except KeyError, var:
+        log.write( "No Ansible directive. Skipping.\n");
+        pass