Commit 43df9b4e authored by nanahira's avatar nanahira

move some vars to utility

parent eac2fca1
0.0.0.0/8 0.0.0.0/8
10.0.0.0/8 10.0.0.0/7
100.64.0.0/10 100.64.0.0/10
127.0.0.0/8 127.0.0.0/8
169.254.0.0/16 169.254.0.0/16
......
...@@ -40,10 +40,22 @@ class InventoryBuilder { ...@@ -40,10 +40,22 @@ class InventoryBuilder {
// console.log(Object.values(this.hosts)); // console.log(Object.values(this.hosts));
const hosts = Object.fromEntries(Object.values(this.hosts).map(h => [h.host, this.host_vars(h)])); const hosts = Object.fromEntries(Object.values(this.hosts).map(h => [h.host, this.host_vars(h)]));
// console.log(hosts); // console.log(hosts);
const result = YAML.stringify({ wg: { hosts } }); const vars = await this.loadUtilities();
const result = YAML.stringify({ wg: { hosts, vars } });
return fs.promises.writeFile('result/inventory.yaml', result); return fs.promises.writeFile('result/inventory.yaml', result);
} }
async loadUtilities() {
const raw_data = _.keyBy(await this.load('configurations'), 'key');
const vars = {
all_subnets: JSON.parse(JSON.stringify(this.all_subnets))
};
for (let col in raw_data) {
vars[col] = raw_data[col].value;
}
return vars;
}
host_vars(host) { host_vars(host) {
const connections = []; const connections = [];
const null_connection = "10000,null"; const null_connection = "10000,null";
...@@ -71,15 +83,14 @@ class InventoryBuilder { ...@@ -71,15 +83,14 @@ class InventoryBuilder {
return { return {
ansible_ssh_user: host.user, ansible_ssh_user: host.user,
address: host.address, address: host.address,
isCN: host.location.startsWith("CN") isCN: host.location.startsWith("CN"),
key: host.wgPrivateKey, key: host.wgPrivateKey,
frpsPort: host.frpsPort, frpsPort: host.frpsPort,
frpToken: host.frpToken, //frpToken: host.frpToken,
//gateways: _.mapValues(this.gateways[host.name], gw => _.pick(gw, ['mark_gateway'])), //gateways: _.mapValues(this.gateways[host.name], gw => _.pick(gw, ['mark_gateway'])),
gateways: _.values(this.gateways[host.name]), gateways: _.values(this.gateways[host.name]),
connections, connections,
lan_interfaces, lan_interfaces
all_subnets: JSON.parse(JSON.stringify(this.all_subnets))
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment