45
|
1 # run key dns lookups everywhere
|
|
2 import subprocess
|
|
3 import tempfile
|
|
4
|
|
5 import requests
|
|
6 from pyinfra import host
|
|
7 from pyinfra.operations import apt, files, server, systemd
|
|
8
|
|
9 def check(name, addr):
|
|
10 server.shell(commands=[
|
|
11 # note: one big string
|
|
12 f"out=`dnsget -q {name}`; "
|
|
13 f'[ -n "$out" ] || exit 1; '
|
|
14 f"if [ $out != {addr} ]; then echo got $out >&2 ; exit 1; fi"
|
|
15 ])
|
|
16
|
|
17 '''
|
|
18 idea: read a file that looks like this:
|
|
19
|
|
20 on host: bang dash slash prime
|
|
21 lookup:
|
|
22 bang 127.0.1.1 10.1.0.1 10.1.0.1 10.5.0.1
|
|
23 bang5 10.5.0.1 10.5.0.1 10.5.0.1 10.5.0.1
|
|
24 dash 10.1.0.5 127.0.1.1 10.1.0.5 10.5.0.5
|
|
25 etc
|
|
26
|
|
27 (or another idea: wireguard everywhere all the time)
|
|
28 '''
|
|
29
|
|
30 # outside k8s
|
|
31 if host.name in ['dash', 'bang', 'slash']:
|
|
32 check('dash', '10.1.0.5')
|
|
33 elif host.name in ['prime']:
|
|
34 check('dash', '10.5.0.5')
|
|
35 else:
|
|
36 check('dash', '10.1.0.5')
|
|
37
|
|
38 if host.name in ['bang']:
|
|
39 check('bang', '10.2.0.1')
|
|
40 elif host.name in ['prime']:
|
|
41 check('bang', '10.5.0.1')
|
|
42 else:
|
|
43 check('bang', '10.2.0.1')
|
|
44
|
|
45 check('bang5', '10.5.0.1')
|
|
46 check('prime', '10.5.0.2')
|
|
47 check('slash', '10.1.0.6')
|
|
48
|
|
49 # inside k8s |