Commit c67d53a1 authored by nanahira's avatar nanahira

generate a switch inventory

parent 649c26fd
......@@ -16,7 +16,7 @@ ip rule add pref 81 to {{subnet}} lookup main || true
# chain for wg origin
iptables -t mangle -N NEXTGEN_ORIGIN
iptables -t mangle -A PREROUTING -m mark --mark 0x0 ! -d 224.0.0.0/3 ! -p ospf -j NEXTGEN_ORIGIN
iptables -t mangle -A PREROUTING -m mark --mark 0x0 ! -p ospf -j NEXTGEN_ORIGIN
iptables -t mangle -N NEXTGEN_SWITCH
iptables -t mangle -A PREROUTING -m mark --mark 0x0 ! -p ospf -m set ! --match-set mycard dst -j NEXTGEN_SWITCH
......
......@@ -4,4 +4,4 @@ IPSET=$2
ADDRESS=$3
cd ansible
ansible all -i ../result/inventory.yaml -u root -m shell -b -a "ipset $OPERATION $IPSET $ADDRESS"
ansible switch -i ../result/inventory.yaml -u root -m shell -b -a "ipset $OPERATION $IPSET $ADDRESS"
......@@ -38,10 +38,17 @@ class InventoryBuilder {
host.wgPublickey = await this.wgPublickey(host.wgPrivateKey);
}
// console.log(Object.values(this.hosts));
const hosts = Object.fromEntries(Object.values(this.hosts).map(h => [h.name, this.host_vars(h)]));
const rawHosts = Object.values(this.hosts).map(h => [h.name, this.host_vars(h)]);
const hosts = Object.fromEntries(rawHosts);
// console.log(hosts);
const vars = await this.loadUtilities();
const result = YAML.stringify({ wg: { hosts, vars } });
const rawHostsForSwitch = rawHosts.map(rh => {
const hostVars = JSON.parse(JSON.stringify(rh[1]));
hostVars.ansible_ssh_host = hostVars.address;
return [rh[0], hostVars];
});
const switchHosts = Object.fromEntries(rawHostsForSwitch);
const result = YAML.stringify({ wg: { hosts, vars }, switch: { hosts: switchHosts, vars: JSON.parse(JSON.stringify(vars)) } });
return fs.promises.writeFile('result/inventory.yaml', result);
}
......@@ -218,7 +225,7 @@ class InventoryBuilder {
}
// frps还是frpc的积分,NAT越有利分越高
gatewayCompareScore(gateway: any): number {
gatewayCompareScore(gateway: any): number {
let score: number = 0xff - gateway.id;
const ipv4Score = ({
"static": 2,
......
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