-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocks.js
More file actions
executable file
·75 lines (67 loc) · 1.7 KB
/
docks.js
File metadata and controls
executable file
·75 lines (67 loc) · 1.7 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
'use strict';
var aws = require('aws-sdk');
var ec2 = new aws.EC2({
accessKeyId: 'AKIAJ3RCYU6FCULAJP2Q',
secretAccessKey: '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',
region: 'us-west-2'
});
var params = {
Filters: [
// Only search for docks in the cluster security group
{
Name: 'instance.group-id',
Values: ['sg-6cd7fb08']
},
// Only fetch instances that are tagged as docks
{
Name: 'tag:role',
Values: ['dock']
},
// Only fetch running instances
{
Name: 'instance-state-name',
Values: ['running']
}
]
};
ec2.describeInstances(params, function (err, data) {
if (err) {
console.error("An error occurred: ", err);
process.exit(1);
}
// Get a set of instances from the describe response
var instances = [];
data.Reservations.forEach(function (res) {
res.Instances.forEach(function (instance) {
instances.push(instance);
});
});
// Map the instances to their private ip addresses
// NOTE This will work locally because of the wilcard ssh proxy in the config
var hosts = instances.map(function (instance) {
return instance.PrivateIpAddress;
});
var hostVars = {};
instances.forEach(function (instance) {
for (var i = 0; i < instance.Tags.length; i++) {
if (instance.Tags[i].Key === 'org') {
hostVars[instance.PrivateIpAddress] = {
host_tags: instance.Tags[i].Value + ',build,run'
};
}
}
});
// Output the resulting JSON
// NOTE http://docs.ansible.com/ansible/developing_inventory.html
console.log(JSON.stringify(
{
docks: {
hosts: hosts
},
_meta : {
hostvars : hostVars
}
}
));
});