comparison net.py @ 15:516a91a3ec08

closer to working netplan
author drewp@bigasterisk.com
date Sat, 13 Nov 2021 12:13:54 -0800
parents 15c5ce7c74b5
children 0c1496e11b8f
comparison
equal deleted inserted replaced
14:ac4d24d01b68 15:516a91a3ec08
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 # todo: netplan could do this, below
12 files.put(src="secrets/wpa_supplicant.conf", dest="/etc/wpa_supplicant/wpa_supplicant.conf") 13 files.put(src="secrets/wpa_supplicant.conf", dest="/etc/wpa_supplicant/wpa_supplicant.conf")
13 14
14 files.template(src='templates/hosts.j2', dest='/etc/hosts') 15 files.template(src='templates/hosts.j2', dest='/etc/hosts')
15 16
16 if host.name == 'prime': 17 if host.name == 'prime':
28 ns = '8.8.8.8' 29 ns = '8.8.8.8'
29 elif host.name in ['dash', 'slash']: 30 elif host.name in ['dash', 'slash']:
30 ns = '10.1.0.1' 31 ns = '10.1.0.1'
31 files.template(src='templates/resolv.conf.j2', dest='/etc/resolv.conf', ns=ns) 32 files.template(src='templates/resolv.conf.j2', dest='/etc/resolv.conf', ns=ns)
32 33
33 if host.name in ['dash', 'slash', 'garage', 'frontbed']: 34 if host.name in ['dash', 'slash', 'garage', 'frontbed', 'dot']:
34 # might need to upgrade pi systemd if there are errors in this part 35 # might need to upgrade pi systemd if there are errors in this part
35 apt.packages(packages=['netplan.io']) 36 apt.packages(packages=['netplan.io'])
36 files.file(path='/etc/netplan/00-installer-config.yaml', present=False) 37 for bad in [
38 '01-netcfg.yaml',
39 '01-network-manager-all.yaml',
40 '00-installer-config.yaml',
41 '99-ansible-written.yaml',
42 '99-dns.conf',
43 ]:
44 files.file(path=f'/etc/netplan/{bad}', present=False)
37 addrs = host.get_fact(Ipv4Addrs) 45 addrs = host.get_fact(Ipv4Addrs)
38 ipv4Interface = host.host_data['interface'] 46 ipv4Interface = host.host_data['interface']
39 ipv4Address = host.host_data['addr'] 47 ipv4Address = host.host_data['addr']
40 files.template(src='templates/netplan.yaml.j2', 48 files.template(src='templates/netplan.yaml.j2',
41 dest='/etc/netplan/99-ansible-written.yaml', 49 dest='/etc/netplan/99-pyinfra-written.yaml',
42 ipv4Interface=ipv4Interface, 50 ipv4Interface=ipv4Interface,
43 ipv4Address=ipv4Address) 51 ipv4Address=ipv4Address)
44 server.shell(commands=['netplan apply']) 52 server.shell(commands=['netplan apply'])
45 53
46 apt.packages(packages=['network-manager'], present=host.name in ['plus']) 54 apt.packages(packages=['network-manager'], present=host.name in ['plus'])