-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (46 loc) · 1.92 KB
/
index.js
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
53
var async = require('async')
module.exports = function(playbook) {
var p
if (Array.isArray(playbook)) {
p = function(context, cb) {
async.series(playbook.map(function(directive) {
// If the directive is a string, execute its content in our context.
if (typeof directive === 'string') return async.apply(exec, directive, context)
// If the directive is an object, grab its first key and require `'nibbler-' + key`.
// This supports a syntax like: `{ apt: { pkg: 'redis-server', state: 'present' } }`
if (typeof directive === 'object' && !Array.isArray(directive)) {
var keys = Object.keys(directive)
// Remark(mmalecki): Ansible seems to enjoy sticking some meta information
// in here too (like a `name` field) - maybe filter those out?
if (keys.length !== 1)
throw new Error('Exactly one key is required for a directive object')
var directiveModule = require('nibbler-' + keys[0])
return async.apply(directiveModule, directive[keys[0]], context)
}
// Enable including "roles" like:
//
// `nginx.js`:
//
// module.exports = [ [ apt, { pkg: 'nginx' } ] ]
//
// `pages.js`:
//
// module.exports = [ [ copy, { src: __dirname, dest: '/var/www' ] ]
//
// `server.js`:
//
// module.exports = [ require('./nginx.js'), require('./pages.js') ]
//
if (Array.isArray(directive) && Array.isArray(directive[0])) {
}
// If directive is anything but those (for example, a function), wrap
// it in an array for the purpose of making it look more like a directive.
directive = Array.isArray(directive) ? directive : [directive]
directive.push(context)
return async.apply.apply(null, directive)
}), cb);
}
}
else p = playbook
return p
}