Step to hook into Ansible
[bootmanager.git] / source / steps / AnsibleHook.py
1 #!/usr/bin/python
2 #
3
4 import os
5
6 from Exceptions import *
7 import utils
8 import systeminfo
9
10 def run_ansible(ansible_path, ansible_hash, playbook_name, log):
11     try:
12         if (ansible_hash):
13             hash_arg = '-U %s'%ansible_hash
14         else:
15             hash_arg = ''
16         utils.sysexec_noerr('ansible-pull -i hosts %s %s %s' % (ansible_path, hash_arg, playbook_name), log )
17     except:
18         pass
19
20
21 def Run( vars, log ):
22     log.write( "\n\nStep: Running Ansible Hook\n" )
23     # make sure we have the variables we need
24     try:
25         ansible_path = vars["ANSIBLE_PATH"]
26         run_level = vars["RUN_LEVEL"]
27         try:
28             ansible_hash = vars["ANSIBLE_HASH"]
29         except KeyError:
30             ansible_hash = None
31
32         if (ansible_path):
33             run_ansible(ansible_path, ansible_hash, "%s.yml"%run_level, log)
34     except KeyError, var:
35         log.write( "No Ansible directive. Skipping.\n");
36         pass