remove modules in infrastructure

This commit is contained in:
egarette@silique.fr 2023-03-02 21:58:24 +01:00
parent bb35d6cf3e
commit 5d969ada38
4 changed files with 40 additions and 41 deletions

View file

@ -55,6 +55,16 @@
loop_control:
label: "{{ item.value['doc'] }}"
# some services (like networkd) did not really stoped
- name: "Stop services"
ansible.builtin.service:
name: "{{ item.value['doc'] }}"
state: stopped
when: item.value['manage'] and item.value['activate'] and item.value['doc'].endswith('.service') and not item.value['doc'].endswith('@.service') and item.value['engine'] != 'none' and item.value['doc'] in services
loop: "{{ vars[inventory_hostname]['services'] | dict2items }}"
loop_control:
label: "{{ item.value['doc'] }}"
- name: "Start services"
when: item.value['manage'] and item.value['activate'] and item.value['doc'].endswith('.service') and not item.value['doc'].endswith('@.service') and item.value['engine'] != 'none'
ansible.builtin.service:

View file

@ -74,7 +74,7 @@ class RisottoInventory(object):
'hosts': servers,
'vars': {
# FIXME
# 'ansible_ssh_host': '192.168.0.100',
# 'ansible_ssh_host': '192.168.0.29',
'ansible_ssh_user': 'root',
'ansible_python_interpreter': '/usr/bin/python3'
}

View file

@ -39,7 +39,7 @@ class Applications:
Returns something link:
{<applicationservice>: seed/<applicationservice>}
"""
applications = {}
applications = {'host': None}
for dataset_directory in self.datasets:
for applicationservice in listdir(dataset_directory):
applicationservice_dir = join(dataset_directory, applicationservice)
@ -59,23 +59,22 @@ class Modules:
"""
def __init__(self,
host_applicationsservices: list,
applicationservices: Applications,
applicationservice_provider: str,
modules_name: list,
modules: dict,
host_applicationsservice: str,
) -> None:
self.application_directories = applicationservices.application_directories
self.module_infos = {}
self.module_infos['host'] = self._load_module_informations('host',
host_applicationsservices,
['host', host_applicationsservice],
is_host=True,
)
for module_name in modules_name:
if module_name == 'host':
raise Exception('forbidden module name: "host"')
self.module_infos[module_name] = self._load_module_informations(module_name,
[applicationservice_provider] + modules[module_name],
[applicationservice_provider, module_name],
is_host=False,
)
@ -120,6 +119,8 @@ class Modules:
raise Exception(f'cannot find application dependency "{appname}"')
cfg.depends.append(appname)
as_dir = self.application_directories[appname]
if not as_dir:
return
self._load_applicationservice_directories(as_dir,
cfg,
)
@ -234,7 +235,7 @@ async def valid_mandatories(config):
msg = f' - {text} ({path})'
supplier = await suboption.information.get('supplier', None)
if supplier:
msg += f' you could add a service that provides {supplier}'
msg += f' you could add a service that provides "{supplier}"'
try:
await config.option(mandatory).value.get()
variables.setdefault(title, []).append(msg)

View file

@ -226,15 +226,14 @@ class Loader:
# load modules associate to this host
modules_name = set()
for name, mod_datas in datas['servers'].items():
if not 'module' in mod_datas:
raise Exception(f'module is mandatory for "{name}"')
modules_name.add(mod_datas['module'])
if not 'applicationservice' in mod_datas:
raise Exception(f'applicationservice is mandatory for "{name}"')
modules_name.add(mod_datas['applicationservice'])
# load modules informations from config files
modules = Modules(datas['applicationservices'],
applicationservices,
modules = Modules(applicationservices,
datas['applicationservice_provider'],
modules_name,
self.servers_json['modules']
datas['applicationservice'],
)
# load host
@ -253,10 +252,10 @@ class Loader:
modules_info = {}
#FIXME ADD TLS in servers !!!
for server_name, server_datas in datas['servers'].items():
module_info = modules.get(server_datas['module'])
module_info = modules.get(server_datas['applicationservice'])
zones_name = server_datas['informations']['zones_name']
values = [f'{server_name}.{zones[zone_name]["domain_name"]}' for zone_name in zones_name]
if server_datas['module'] == 'tls':
if server_datas['applicationservice'] == 'tls':
true_host_name = f'{server_name}.{zones[list(zones)[0]]["domain_name"]}'
else:
true_host_name = values[0]
@ -265,7 +264,7 @@ class Loader:
'global:server_names': values,
'global:zones_name': zones_name,
'global:zones_list': list(range(len(zones_name))),
'global:module_name': server_datas['module'],
'global:module_name': server_datas['applicationservice'],
}
server_datas['server_name'] = true_host_name
functions_files |= set(module_info.functions_file)
@ -281,28 +280,19 @@ class Loader:
def add_tls(self):
zones = set()
rp_module_name = None
dns_module_name = None
for module_name, applicationservices in self.servers_json['modules'].items():
if 'nginx-reverse-proxy' in applicationservices:
rp_module_name = module_name
if dns_module_name:
break
if 'unbound' in applicationservices:
dns_module_name = module_name
if rp_module_name:
break
if not rp_module_name or not dns_module_name:
rp_module_name = dns_module_name = None
for host_name, host_datas in self.servers_json['hosts'].items():
for host in self.servers_json['hosts'].values():
zones = [None, None]
for server_name, datas in host_datas['servers'].items():
if datas['module'] == 'tls':
for server_name, datas in host['servers'].items():
if datas['applicationservice'] == 'tls':
raise Exception(f'forbidden module name "tls" for server {server_name}')
if datas['module'] == rp_module_name and len(datas['informations']['zones_name']) > 0:
#FIXME use provider!
if datas['applicationservice'] == 'nginx-reverse-proxy' and len(datas['informations']['zones_name']) > 0:
if dns_module_name:
break
# always add tls machine in second zone of reverse proxy
zones[1] = datas['informations']['zones_name'][0]
if datas['module'] == dns_module_name:
if datas['applicationservice'] == 'unbound':
# always add tls machine in second zone of reverse proxy
zones[0] = datas['informations']['zones_name'][0]
if None in zones:
@ -310,15 +300,13 @@ class Loader:
else:
if zones[0] == zones[1]:
zones = [zones[0]]
host_datas['servers']['tls'] = {'module': 'tls',
'informations': {'zones_name': list(zones)},
}
for module_name in self.servers_json['modules']:
if module_name == 'tls':
raise Exception('forbidden module name: "tls"')
self.servers_json['modules']['tls'] = ['tls']
host['servers']['tls'] = {'applicationservice': 'tls',
'informations': {'zones_name': list(zones)},
}
def load_dictionaries(self, cfg, module_info, server_name, rougail):
if not module_info.dictionaries_dir:
raise Exception(f'server "{server_name}" has any dictionaries!')
cfg['dictionaries_dir'] = module_info.dictionaries_dir
cfg['extra_dictionaries'] = module_info.extra_dictionaries
cfg['functions_file'] = module_info.functions_file
@ -362,7 +350,7 @@ class Loader:
for datas in hosts_datas['servers'].values():
server_name = datas['server_name']
information = config.option(normalize_family(server_name)).information
await information.set('module', datas['module'])
await information.set('module', datas['applicationservice'])
await information.set('templates_dir', self.templates_dir[server_name])
await information.set('patches_dir', self.patches_dir[server_name])
await information.set('functions_files', self.functions_files[server_name])