2021-04-02 16:57:13 +00:00
|
|
|
from bundlewrap.exceptions import BundleError
|
|
|
|
|
2023-09-09 15:48:22 +00:00
|
|
|
supported_os = {
|
|
|
|
'debian': {
|
|
|
|
10: 'buster',
|
|
|
|
11: 'bullseye',
|
|
|
|
12: 'bookworm',
|
|
|
|
99: 'unstable',
|
|
|
|
},
|
|
|
|
'raspbian': {
|
|
|
|
10: 'buster',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
2021-04-02 16:57:13 +00:00
|
|
|
CONFLICTING_BUNDLES = {
|
|
|
|
'apt',
|
|
|
|
'nginx',
|
2021-04-24 07:44:31 +00:00
|
|
|
'telegraf',
|
2021-04-02 16:57:13 +00:00
|
|
|
'users',
|
|
|
|
}
|
|
|
|
|
|
|
|
if any(node.has_bundle(i) for i in CONFLICTING_BUNDLES):
|
|
|
|
raise BundleError(f'{node.name}: bundle:c3voc-addons conflicts with bundles: {", ".join(sorted(CONFLICTING_BUNDLES))}')
|
2021-01-17 09:15:49 +00:00
|
|
|
|
2021-01-16 19:57:33 +00:00
|
|
|
pkg_apt = {
|
|
|
|
'apt-transport-https': {},
|
|
|
|
|
|
|
|
'build-essential': {},
|
|
|
|
'curl': {},
|
|
|
|
'git': {},
|
|
|
|
'grep': {},
|
|
|
|
'gzip': {},
|
|
|
|
'htop': {},
|
|
|
|
'jq': {},
|
|
|
|
'less': {},
|
|
|
|
'mtr': {},
|
|
|
|
'ncdu': {},
|
|
|
|
'netcat': {},
|
|
|
|
'python3': {},
|
|
|
|
'python3-dev': {},
|
2021-05-23 12:54:24 +00:00
|
|
|
'python3-setuptools': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_pip:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'python3-pip': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_pip:',
|
|
|
|
},
|
|
|
|
},
|
2021-01-16 19:57:33 +00:00
|
|
|
'python3-virtualenv': {},
|
|
|
|
'rsync': {},
|
|
|
|
'tar': {},
|
|
|
|
'tmux': {},
|
|
|
|
'tree': {},
|
|
|
|
'wget': {},
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
if node.metadata.get('apt/packages', {}):
|
2021-01-16 19:57:33 +00:00
|
|
|
for package, options in node.metadata['apt']['packages'].items():
|
|
|
|
pkg_apt[package] = options
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
'systemd-reload': {
|
|
|
|
'command': 'systemctl daemon-reload',
|
|
|
|
'cascade_skip': False,
|
|
|
|
'triggered': True,
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:',
|
|
|
|
},
|
|
|
|
},
|
2023-09-09 15:48:22 +00:00
|
|
|
'apt_update': {
|
|
|
|
'command': 'apt-get update',
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_apt:',
|
|
|
|
},
|
|
|
|
'triggered': True,
|
|
|
|
'cascade_skip': False,
|
|
|
|
},
|
2021-01-16 19:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
directories = {
|
|
|
|
'/etc/nginx/sites-enabled': {
|
|
|
|
'purge': True,
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-17 17:43:30 +00:00
|
|
|
files = {
|
2021-02-12 17:12:24 +00:00
|
|
|
'/etc/kernel/postinst.d/unattended-upgrades': {
|
|
|
|
'source': 'kernel-postinst.d',
|
|
|
|
},
|
2021-05-11 04:21:42 +00:00
|
|
|
'/etc/upgrade-and-reboot.conf': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
},
|
2021-01-17 17:43:30 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_unattended_upgrades': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
|
|
|
'/usr/local/sbin/upgrade-and-reboot': {
|
2021-05-11 04:21:42 +00:00
|
|
|
'mode': '0700',
|
|
|
|
},
|
|
|
|
'/usr/local/sbin/do-unattended-upgrades': {
|
2021-01-17 17:43:30 +00:00
|
|
|
'content_type': 'mako',
|
|
|
|
'mode': '0700',
|
|
|
|
'context': {
|
2022-03-06 11:57:48 +00:00
|
|
|
'additional_update_commands': node.metadata.get('apt/additional_update_commands', set()),
|
2021-05-11 04:21:42 +00:00
|
|
|
'clean_old_kernels': node.metadata.get('apt/clean_old_kernels', True),
|
|
|
|
'restart_triggers': node.metadata.get('apt/restart_triggers', {}),
|
2021-01-17 17:43:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-09 15:48:22 +00:00
|
|
|
for name, data in node.metadata.get('apt/repos', {}).items():
|
|
|
|
files['/etc/apt/sources.list.d/{}.list'.format(name)] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'content': ("\n".join(sorted(data['items']))).format(
|
|
|
|
os=node.os,
|
|
|
|
os_release=supported_os[node.os][node.os_version[0]],
|
|
|
|
),
|
|
|
|
'triggers': {
|
|
|
|
'action:apt_update',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
}
|
|
|
|
|
|
|
|
files['/etc/apt/trusted.gpg.d/{}.list.asc'.format(name)] = {
|
|
|
|
'source': 'gpg-keys/{}.asc'.format(name),
|
|
|
|
'triggers': {
|
|
|
|
'action:apt_update',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-05 10:41:41 +00:00
|
|
|
for crontab, content in node.metadata.get('cron/jobs', {}).items():
|
2021-01-19 12:34:23 +00:00
|
|
|
files['/etc/cron.d/{}'.format(crontab)] = {
|
|
|
|
'source': 'cron_template',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'cron': content,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for vhost, config in node.metadata.get('nginx/vhosts', {}).items():
|
2021-01-16 19:57:33 +00:00
|
|
|
if not 'domain' in config:
|
|
|
|
config['domain'] = vhost
|
|
|
|
|
|
|
|
files['/etc/nginx/sites-available/{}'.format(vhost)] = {
|
|
|
|
'source': 'site_template',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'vhost': vhost,
|
|
|
|
**config,
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
symlinks['/etc/nginx/sites-enabled/{}'.format(vhost)] = {
|
|
|
|
'target': '/etc/nginx/sites-available/{}'.format(vhost),
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if not 'webroot' in config:
|
|
|
|
directories['/var/www/{}'.format(vhost)] = config.get('webroot_config', {})
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'nginx': {},
|
2021-01-17 17:43:30 +00:00
|
|
|
'apt-daily.timer': {
|
|
|
|
'running': False,
|
|
|
|
'enabled': False,
|
|
|
|
},
|
|
|
|
'apt-daily-upgrade.timer': {
|
|
|
|
'running': False,
|
|
|
|
'enabled': False,
|
|
|
|
},
|
2021-01-16 19:57:33 +00:00
|
|
|
}
|