-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebrew
52 lines (43 loc) · 1.67 KB
/
firebrew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import generators
from __future__ import division
import pipes
from ansible.module_utils.basic import *
class Firebrew(object):
STATUS_SUCCESS = 0
STATUS_FAILURE = 1
STATUS_NOT_CHANGED = 2
def __init__(self, AnsibleModule = AnsibleModule):
self.module = AnsibleModule(
argument_spec = dict(
state = dict(type='str', default='present', choices=['present', 'absent']),
name = dict(type='str', required=True),
base_dir = dict(type='str'),
profile = dict(type='str'),
firefox = dict(type='str')
)
)
def build_command(self):
params = self.module.params
command = [
self.module.get_bin_path('firebrew'),
{'present': 'install', 'absent': 'uninstall'}[params['state']],
pipes.quote(params['name'])
]
for opt in ['base_dir','profile','firefox']:
if opt in params and params[opt] != None and params[opt].strip() != '':
command.append('--%s=%s' % (opt.replace('_','-'), pipes.quote(params[opt])))
return ' '.join(command)
def execute(self):
(rc,out,err) = self.module.run_command(self.build_command())
if rc == self.STATUS_SUCCESS:
self.module.exit_json(changed=True)
elif rc == self.STATUS_NOT_CHANGED:
self.module.exit_json(changed=False)
else:
self.module.fail_json(msg = err)
if __name__ == '__main__':
Firebrew().execute()