From: Sapan Bhatia Date: Tue, 1 Apr 2014 12:43:13 +0000 (-0400) Subject: Step to hook into Ansible X-Git-Tag: bootmanager-5.2-5~1^2~9 X-Git-Url: http://git.onelab.eu/?p=bootmanager.git;a=commitdiff_plain;h=7b5214d6358e7aa2599abf78e455dcd0cd96cf96 Step to hook into Ansible --- diff --git a/source/BootManager.py b/source/BootManager.py index 68c5052..32d7ba8 100755 --- a/source/BootManager.py +++ b/source/BootManager.py @@ -277,6 +277,7 @@ class BootManager: 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() @@ -289,6 +290,8 @@ class BootManager: 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'): diff --git a/source/steps/AnsibleHook.py b/source/steps/AnsibleHook.py new file mode 100644 index 0000000..5275e72 --- /dev/null +++ b/source/steps/AnsibleHook.py @@ -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