2021-04-02 18:57:13 +02:00
|
|
|
from bundlewrap.exceptions import BundleError
|
|
|
|
|
2020-08-29 21:10:22 +02:00
|
|
|
supported_os = {
|
|
|
|
'debian': {
|
|
|
|
10: 'buster',
|
2020-11-12 18:40:19 +01:00
|
|
|
11: 'bullseye',
|
2020-10-09 18:12:49 +02:00
|
|
|
99: 'unstable',
|
2020-08-29 21:10:22 +02:00
|
|
|
},
|
2020-10-03 18:36:29 +02:00
|
|
|
'raspbian': {
|
|
|
|
10: 'buster',
|
|
|
|
},
|
2020-08-29 21:10:22 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:57:13 +02:00
|
|
|
try:
|
|
|
|
supported_os[node.os][node.os_version[0]]
|
|
|
|
except (KeyError, IndexError):
|
|
|
|
raise BundleError(f'{node.name}: OS {node.os} {node.os_version} is not supported by bundle:apt')
|
2020-08-29 21:10:22 +02:00
|
|
|
|
|
|
|
|
2020-02-29 14:42:29 +00:00
|
|
|
actions = {
|
|
|
|
'apt_update': {
|
|
|
|
'command': 'apt-get update',
|
2020-08-20 10:59:45 +02:00
|
|
|
'needed_by': {
|
2020-02-29 14:42:29 +00:00
|
|
|
'pkg_apt:',
|
2020-08-20 10:59:45 +02:00
|
|
|
},
|
2020-02-29 14:42:29 +00:00
|
|
|
'triggered': True,
|
|
|
|
'cascade_skip': False,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
files = {
|
2021-05-08 08:31:04 +02:00
|
|
|
'/etc/apt/sources.list': {
|
|
|
|
'source': 'sources.list-{}-{}'.format(node.os, supported_os[node.os][node.os_version[0]]),
|
|
|
|
'triggers': {
|
|
|
|
'action:apt_update',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/cloud': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
|
|
|
'/etc/kernel/postinst.d/unattended-upgrades': {
|
|
|
|
'source': 'kernel-postinst.d',
|
2020-11-10 09:50:20 +01:00
|
|
|
'mode': '0755',
|
|
|
|
},
|
2021-05-08 08:31:04 +02:00
|
|
|
'/etc/netplan': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
|
|
|
'/etc/upgrade-and-reboot.conf': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
},
|
2020-10-18 15:33:41 +02:00
|
|
|
'/usr/local/sbin/upgrade-and-reboot': {
|
2021-05-08 08:31:04 +02:00
|
|
|
'mode': '0700',
|
|
|
|
},
|
|
|
|
'/usr/local/sbin/do-unattended-upgrades': {
|
2020-02-29 14:42:29 +00:00
|
|
|
'content_type': 'mako',
|
2020-10-18 15:33:41 +02:00
|
|
|
'mode': '0700',
|
2020-08-29 21:10:22 +02:00
|
|
|
'context': {
|
2022-03-06 12:49:46 +01:00
|
|
|
'additional_update_commands': node.metadata.get('apt/additional_update_commands', set()),
|
2021-04-02 08:11:17 +02:00
|
|
|
'clean_old_kernels': node.metadata.get('apt/clean_old_kernels', True),
|
2021-04-02 08:12:51 +02:00
|
|
|
'restart_triggers': node.metadata.get('apt/restart_triggers', {}),
|
2020-08-29 21:10:22 +02:00
|
|
|
}
|
2020-02-29 14:42:29 +00:00
|
|
|
},
|
2021-05-08 08:31:04 +02:00
|
|
|
'/usr/local/share/icinga/plugins/check_unattended_upgrades': {
|
|
|
|
'mode': '0755',
|
2020-08-20 11:07:18 +02:00
|
|
|
},
|
|
|
|
'/var/lib/cloud': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
2020-02-29 14:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
directories = {
|
2020-08-29 21:10:22 +02:00
|
|
|
'/etc/apt/sources.list.d': {
|
|
|
|
'purge': True,
|
2020-10-03 18:36:29 +02:00
|
|
|
'triggers': {
|
|
|
|
'action:apt_update',
|
|
|
|
},
|
2020-08-29 21:10:22 +02:00
|
|
|
},
|
2020-02-29 14:42:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 15:10:59 +01:00
|
|
|
svc_systemd = {
|
|
|
|
'apt-daily.timer': {
|
|
|
|
'running': False,
|
|
|
|
'enabled': False,
|
|
|
|
},
|
|
|
|
'apt-daily-upgrade.timer': {
|
|
|
|
'running': False,
|
|
|
|
'enabled': False,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-29 14:42:29 +00:00
|
|
|
pkg_apt = {
|
|
|
|
'apt-transport-https': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
|
|
|
|
'arping': {},
|
|
|
|
'at': {},
|
2020-10-16 19:12:26 +02:00
|
|
|
'build-essential': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
'bzip2': {},
|
|
|
|
'curl': {},
|
|
|
|
'diffutils': {},
|
|
|
|
'dnsutils': {},
|
2020-10-16 19:12:26 +02:00
|
|
|
'git': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
'grep': {},
|
|
|
|
'gzip': {},
|
|
|
|
'htop': {},
|
|
|
|
'jq': {},
|
|
|
|
'less': {},
|
|
|
|
'logrotate': {},
|
|
|
|
'lsof': {},
|
|
|
|
'mailutils': {},
|
|
|
|
'manpages': {},
|
|
|
|
'moreutils': {},
|
|
|
|
'mount': {},
|
|
|
|
'mtr': {},
|
|
|
|
'ncdu': {},
|
2021-08-17 16:42:26 +02:00
|
|
|
'ncurses-term': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
'netcat': {},
|
|
|
|
'nmap': {},
|
|
|
|
'python3': {},
|
2020-10-16 19:14:15 +02:00
|
|
|
'python3-dev': {},
|
2021-05-23 12:24:00 +02:00
|
|
|
'python3-setuptools': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_pip:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'python3-pip': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_pip:',
|
|
|
|
},
|
|
|
|
},
|
2020-09-06 12:04:56 +02:00
|
|
|
'python3-virtualenv': {},
|
2020-11-13 12:37:26 +01:00
|
|
|
'rsync': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
'tar': {},
|
|
|
|
'tcpdump': {},
|
|
|
|
'telnet': {},
|
|
|
|
'tmux': {},
|
|
|
|
'tree': {},
|
|
|
|
'unzip': {},
|
2021-02-18 14:23:43 +01:00
|
|
|
'vim': {},
|
2020-08-18 15:46:42 +02:00
|
|
|
'wget': {},
|
|
|
|
'whois': {},
|
|
|
|
'zip': {},
|
2020-08-20 11:07:18 +02:00
|
|
|
|
|
|
|
'cloud-init': {
|
|
|
|
'installed': False,
|
|
|
|
},
|
2023-01-28 18:07:31 +01:00
|
|
|
'molly-guard': {
|
|
|
|
'installed': False,
|
|
|
|
},
|
2020-08-20 11:07:18 +02:00
|
|
|
'netplan.io': {
|
|
|
|
'installed': False,
|
|
|
|
},
|
2020-08-30 11:14:31 +02:00
|
|
|
'popularity-contest': {
|
|
|
|
'installed': False,
|
|
|
|
},
|
2020-10-18 15:33:41 +02:00
|
|
|
'unattended-upgrades': {
|
|
|
|
'installed': False,
|
|
|
|
},
|
2020-02-29 14:42:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 13:32:59 +02:00
|
|
|
if node.os_version[0] >= 11:
|
|
|
|
symlinks = {
|
|
|
|
'/usr/bin/python': {
|
|
|
|
'target': '/usr/bin/python3',
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:python3',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-08-20 11:07:18 +02:00
|
|
|
|
2021-02-18 18:12:25 +01:00
|
|
|
for name, data in node.metadata.get('apt/repos', {}).items():
|
2020-02-29 14:42:29 +00:00
|
|
|
files['/etc/apt/sources.list.d/{}.list'.format(name)] = {
|
|
|
|
'content_type': 'mako',
|
2020-08-30 12:06:19 +02:00
|
|
|
'content': ("\n".join(sorted(data['items']))).format(
|
|
|
|
os=node.os,
|
|
|
|
os_release=supported_os[node.os][node.os_version[0]],
|
|
|
|
),
|
2020-08-20 10:59:45 +02:00
|
|
|
'triggers': {
|
2020-02-29 14:42:29 +00:00
|
|
|
'action:apt_update',
|
2020-08-20 10:59:45 +02:00
|
|
|
},
|
2020-02-29 14:42:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 10:59:45 +02:00
|
|
|
if data.get('install_gpg_key', True):
|
|
|
|
files['/etc/apt/sources.list.d/{}.list'.format(name)]['needs'] = {
|
|
|
|
'file:/etc/apt/trusted.gpg.d/{}.list.asc'.format(name),
|
|
|
|
}
|
2020-02-29 14:42:29 +00:00
|
|
|
|
2020-08-20 10:59:45 +02:00
|
|
|
files['/etc/apt/trusted.gpg.d/{}.list.asc'.format(name)] = {
|
|
|
|
'source': 'gpg-keys/{}.asc'.format(name),
|
|
|
|
'triggers': {
|
|
|
|
'action:apt_update',
|
|
|
|
},
|
|
|
|
}
|
2020-02-29 14:42:29 +00:00
|
|
|
|
2021-04-30 13:30:10 +02:00
|
|
|
for package, options in node.metadata.get('apt/packages', {}).items():
|
|
|
|
pkg_apt[package] = options
|