Mercurial > code > home > repos > infra
comparison net.py @ 12:15c5ce7c74b5
refactor, cleanup, split large deploys
author | drewp@bigasterisk.com |
---|---|
date | Thu, 11 Nov 2021 23:31:21 -0800 |
parents | 82e46d7ff527 |
children | 516a91a3ec08 |
comparison
equal
deleted
inserted
replaced
11:82e46d7ff527 | 12:15c5ce7c74b5 |
---|---|
7 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] | 7 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
8 is_wifi = host.name in ['frontdoor', 'living', 'plus'] | 8 is_wifi = host.name in ['frontdoor', 'living', 'plus'] |
9 ssh_host = host.host_data.get('ssh_hostname', host.name) | 9 ssh_host = host.host_data.get('ssh_hostname', host.name) |
10 | 10 |
11 if is_wifi: | 11 if is_wifi: |
12 files.put(src="files/wpa_supplicant.conf", dest="/etc/wpa_supplicant/wpa_supplicant.conf") | 12 files.put(src="secrets/wpa_supplicant.conf", dest="/etc/wpa_supplicant/wpa_supplicant.conf") |
13 | 13 |
14 files.template(src='templates/hosts.j2', dest='/etc/hosts') | 14 files.template(src='templates/hosts.j2', dest='/etc/hosts') |
15 | 15 |
16 if host.name == 'prime': | 16 if host.name == 'prime': |
17 # prime should have gotten this through netplan, but i give up. | 17 # prime should have gotten this through netplan, but i give up. |
28 ns = '8.8.8.8' | 28 ns = '8.8.8.8' |
29 elif host.name in ['dash', 'slash']: | 29 elif host.name in ['dash', 'slash']: |
30 ns = '10.1.0.1' | 30 ns = '10.1.0.1' |
31 files.template(src='templates/resolv.conf.j2', dest='/etc/resolv.conf', ns=ns) | 31 files.template(src='templates/resolv.conf.j2', dest='/etc/resolv.conf', ns=ns) |
32 | 32 |
33 if host.name in ['dash', 'slash', 'garage']: | 33 if host.name in ['dash', 'slash', 'garage', 'frontbed']: |
34 # might need to upgrade pi systemd if there are errors in this part | 34 # might need to upgrade pi systemd if there are errors in this part |
35 apt.packages(packages=['netplan.io']) | 35 apt.packages(packages=['netplan.io']) |
36 files.file(path='/etc/netplan/00-installer-config.yaml', present=False) | 36 files.file(path='/etc/netplan/00-installer-config.yaml', present=False) |
37 addrs = host.get_fact(Ipv4Addrs) | 37 addrs = host.get_fact(Ipv4Addrs) |
38 ipv4Interface = host.host_data['interface'] | 38 ipv4Interface = host.host_data['interface'] |
39 ipv4Address = host.host_data['addr'] | 39 ipv4Address = host.host_data['addr'] |
40 files.template(src='templates/netplan_dns.yaml.j2', | 40 files.template(src='templates/netplan.yaml.j2', |
41 dest='/etc/netplan/99-ansible-written.yaml', | 41 dest='/etc/netplan/99-ansible-written.yaml', |
42 ipv4Interface=ipv4Interface, | 42 ipv4Interface=ipv4Interface, |
43 ipv4Address=ipv4Address) | 43 ipv4Address=ipv4Address) |
44 server.shell(commands=['netplan apply']) | 44 server.shell(commands=['netplan apply']) |
45 | 45 |
62 systemd.service(service='dnsmasq', enabled=False, running=False) | 62 systemd.service(service='dnsmasq', enabled=False, running=False) |
63 files.directory(path='/opt/dnsmasq') | 63 files.directory(path='/opt/dnsmasq') |
64 | 64 |
65 for net_name in ['10.1', '10.2', '10.5']: | 65 for net_name in ['10.1', '10.2', '10.5']: |
66 files.directory(path=f'/opt/dnsmasq/{net_name}') | 66 files.directory(path=f'/opt/dnsmasq/{net_name}') |
67 files.template(src='templates/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name) | 67 files.template(src='templates/dnsmasq/dnsmasq.conf.j2', dest=f'/opt/dnsmasq/{net_name}/dnsmasq.conf', net=net_name) |
68 files.template(src='templates/dhcp_hosts_file.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) | 68 files.template(src='templates/dnsmasq/hosts.j2', dest=f'/opt/dnsmasq/{net_name}/hosts', net=net_name) |
69 files.template(src='templates/dhcp_hosts.j2', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) | 69 files.template(src='templates/dnsmasq/dhcp_hosts.j2', dest=f'/opt/dnsmasq/{net_name}/dhcp_hosts', net=net_name) |
70 | 70 |
71 files.template(src='templates/dnsmasq.service.j2', dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', net=net_name) | 71 files.template(src='templates/dnsmasq/dnsmasq.service.j2', |
72 dest=f'/etc/systemd/system/dnsmasq_{net_name}.service', | |
73 net=net_name) | |
72 systemd.service(service=f'dnsmasq_{net_name}', restarted=True, daemon_reload=True) | 74 systemd.service(service=f'dnsmasq_{net_name}', restarted=True, daemon_reload=True) |
73 | 75 |
74 if host.name == 'prime': | 76 if host.name == 'prime': |
75 # using digitalocean network config: | 77 # using digitalocean network config: |
76 # https://cloud.digitalocean.com/networking/firewalls/f68899ae-1aac-4469-b379-59ce2bbc988f/droplets?i=7c5072 | 78 # https://cloud.digitalocean.com/networking/firewalls/f68899ae-1aac-4469-b379-59ce2bbc988f/droplets?i=7c5072 |