2021-09-16 17:30:36 +00:00
|
|
|
from inspect import cleandoc
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from bundlewrap.utils.text import italic
|
|
|
|
|
2021-01-23 11:05:59 +00:00
|
|
|
files = {
|
|
|
|
'/etc/default/locale': {
|
2021-02-18 13:51:33 +00:00
|
|
|
'content_type': 'mako',
|
2021-01-24 06:49:49 +00:00
|
|
|
'needs': {
|
2021-01-23 11:05:59 +00:00
|
|
|
'action:locale-gen',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/hosts': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
},
|
2021-02-24 18:24:56 +00:00
|
|
|
'/etc/htoprc.global': {
|
|
|
|
'source': 'htoprc',
|
|
|
|
},
|
2021-09-16 17:30:36 +00:00
|
|
|
'/etc/motd': {
|
|
|
|
'content': '',
|
|
|
|
},
|
2022-11-04 06:28:14 +00:00
|
|
|
'/etc/environment': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'before': {
|
|
|
|
'action:',
|
|
|
|
'pkg_apt:',
|
|
|
|
'pkg_pacman:',
|
|
|
|
},
|
|
|
|
},
|
2021-05-23 12:53:45 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 13:49:45 +00:00
|
|
|
if node.has_any_bundle([
|
|
|
|
'dovecot',
|
|
|
|
'nginx',
|
|
|
|
'postfix',
|
|
|
|
]):
|
|
|
|
actions['generate-dhparam'] = {
|
|
|
|
'command': 'openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048',
|
|
|
|
'unless': 'test -f /etc/ssl/certs/dhparam.pem',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-23 12:53:45 +00:00
|
|
|
locale_needs = set()
|
2023-11-29 15:41:03 +00:00
|
|
|
for locale in sorted(node.metadata.get('locale/installed')):
|
2021-05-23 12:53:45 +00:00
|
|
|
actions[f'ensure_locale_{locale}_is_enabled'] = {
|
|
|
|
'command': f"sed -i '/{locale}/s/^# *//g' /etc/locale.gen",
|
|
|
|
'unless': f"grep -e '^{locale}' /etc/locale.gen",
|
2021-01-23 11:05:59 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:locale-gen',
|
|
|
|
},
|
2021-05-23 12:53:45 +00:00
|
|
|
'needs': locale_needs,
|
|
|
|
}
|
|
|
|
locale_needs = {f'action:ensure_locale_{locale}_is_enabled'}
|
2021-01-23 11:05:59 +00:00
|
|
|
|
2024-05-05 13:49:45 +00:00
|
|
|
actions['locale-gen'] = {
|
|
|
|
'triggered': True,
|
|
|
|
'command': 'locale-gen',
|
2021-01-23 11:05:59 +00:00
|
|
|
}
|
2021-09-16 17:30:36 +00:00
|
|
|
|
|
|
|
description = []
|
|
|
|
|
|
|
|
if not node.metadata.get('icinga_options/exclude_from_monitoring', False):
|
2023-09-09 12:12:24 +00:00
|
|
|
description.append('icingaweb2: https://icinga.franzi.business/monitoring/host/show?host={}'.format(node.name))
|
2021-09-16 17:30:36 +00:00
|
|
|
|
|
|
|
if node.has_bundle('telegraf'):
|
|
|
|
description.append('Grafana: https://grafana.kunsmann.eu/d/{}'.format(UUID(int=node.magic_number).hex[:10]))
|
|
|
|
|
|
|
|
if (
|
|
|
|
not node.metadata.get('icinga_options/exclude_from_monitoring', False) or
|
|
|
|
node.has_bundle('telegraf')
|
|
|
|
):
|
|
|
|
description.append('') # divider line
|
|
|
|
|
|
|
|
if node.metadata.get('nginx/vhosts', {}):
|
|
|
|
description.append('nginx vhosts:')
|
|
|
|
|
|
|
|
for vname, vconfig in sorted(node.metadata.get('nginx/vhosts', {}).items()):
|
|
|
|
if vconfig.get('ssl', 'letsencrypt') is not None:
|
|
|
|
proto = 'https'
|
|
|
|
else:
|
|
|
|
proto = 'http'
|
|
|
|
|
|
|
|
domain = vconfig.get('domain', vname)
|
|
|
|
|
|
|
|
description.append(' {}: {}://{}{}'.format(
|
|
|
|
vname,
|
|
|
|
proto,
|
|
|
|
domain,
|
|
|
|
vconfig.get('website_check_path', '/'),
|
|
|
|
))
|
|
|
|
|
|
|
|
if node.metadata.get('description', []):
|
|
|
|
description.append('') # divider line
|
|
|
|
|
|
|
|
for line in node.metadata.get('description', []):
|
|
|
|
description.append('# {}'.format(italic(line)))
|
|
|
|
|
|
|
|
if description:
|
|
|
|
files['/etc/node.description'] = {
|
|
|
|
'content': '\n'.join(description) + '\n',
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
files['/etc/node.description'] = {
|
|
|
|
'delete': True,
|
|
|
|
}
|