-
Notifications
You must be signed in to change notification settings - Fork 122
/
ansible-playbook.js
43 lines (34 loc) · 1.13 KB
/
ansible-playbook.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
/**
* Copyright (c) Forward Email LLC
* SPDX-License-Identifier: BUSL-1.1
*/
const process = require('node:process');
const fs = require('node:fs');
const path = require('node:path');
const { execSync } = require('node:child_process');
const parse = require('parse-git-config');
const env = path.join(__dirname, '.env.production');
if (!fs.existsSync(env))
throw new Error(`.env.production file missing: ${env}`);
if (!fs.statSync(env).isFile())
throw new Error(`.env.production file missing: ${env}`);
// this will populate process.env with
// environment variables from dot env file
require('@ladjs/env')({
path: env,
defaults: path.join(__dirname, '.env.defaults'),
schema: path.join(__dirname, '.env.schema')
});
// set git config url
process.env.GITHUB_REPO = parse.sync({
path: path.join(__dirname, '.git', 'config')
})['remote "origin"'].url;
if (!execSync('which ansible-playbook'))
throw new Error('ansible-playbook is required to be installed on this os');
try {
execSync(`ansible-playbook -i hosts.yml ${process.argv.slice(2).join(' ')}`, {
stdio: 'inherit'
});
} catch (err) {
console.error(err.stack);
}