Refactor filter_plugins
This commit is contained in:
parent
8ee096949d
commit
bdf1f8891b
14 changed files with 34 additions and 30 deletions
|
|
@ -1,9 +1,8 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'list_prefix_suffix': self.list_prefix_suffix,
|
||||
'list_prefix_path_suffix': self.list_prefix_path_suffix,
|
||||
'postgresql_restart_required': self.postgresql_restart_required,
|
||||
'utils_list_prefix_suffix': self.list_prefix_suffix,
|
||||
'utils_list_prefix_path_suffix': self.list_prefix_path_suffix,
|
||||
}
|
||||
|
||||
def list_prefix_suffix(self, values, prefix, suffix):
|
||||
|
|
@ -18,9 +17,3 @@ class FilterModule(object):
|
|||
for value in values:
|
||||
result.append(f"{prefix}{value}{suffix}")
|
||||
return result
|
||||
|
||||
def postgresql_restart_required(self, results):
|
||||
for result in results:
|
||||
if result.get('restart_required') and result.get('changed'):
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ backup_yml:
|
|||
|
||||
backends: "{{ backup_backends | mandatory }}"
|
||||
|
||||
locations: "{{ backup_list | map_backup_locations(backup_backends | mandatory, backup_default_hooks) }}"
|
||||
locations: "{{ backup_list | backup_map_locations(backup_backends | mandatory, backup_default_hooks) }}"
|
||||
|
||||
global: "{{ backup_global }}"
|
||||
|
||||
|
|
@ -55,6 +55,6 @@ backup_yml_all:
|
|||
|
||||
backends: "{{ backup_backends | mandatory }}"
|
||||
|
||||
locations: "{{ backup_list_all | map_backup_locations(backup_backends | mandatory, backup_default_hooks) }}"
|
||||
locations: "{{ backup_list_all | backup_map_locations(backup_backends | mandatory, backup_default_hooks) }}"
|
||||
|
||||
global: "{{ backup_global }}"
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ def hooks_add_or_create(location, key, value):
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'map_backup_locations': self.map_backup_locations
|
||||
'backup_map_locations': self.map_locations
|
||||
}
|
||||
|
||||
def map_backup_locations(self, locations, backends, hooks):
|
||||
def map_locations(self, locations, backends, hooks):
|
||||
result = {}
|
||||
backends_list = list(backends.keys())
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
gatus_external_endpoints_backups: "{{ hostvars | hosts_backup_to_gatus() }}"
|
||||
gatus_external_endpoints_backups: "{{ hostvars | gatus_from_hosts_backup() }}"
|
||||
|
||||
gatus_endpoints_hosts: "{{ opentofu.hosts | hosts_to_gatus() }}"
|
||||
gatus_endpoints_services: "{{ all_services | services_to_gatus() }}"
|
||||
gatus_endpoints_hosts: "{{ opentofu.hosts | gatus_from_hosts() }}"
|
||||
gatus_endpoints_services: "{{ all_services | gatus_from_services() }}"
|
||||
|
||||
gatus_federation_tester: "https://federationtester.matrix.org/api/report?server_name=msrg.cc"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'hosts_to_gatus': self.hosts_to_gatus,
|
||||
'hosts_backup_to_gatus': self.hosts_backup_to_gatus,
|
||||
'services_to_gatus': self.services_to_gatus,
|
||||
'gatus_from_hosts': self.from_hosts,
|
||||
'gatus_from_hosts_backup': self.from_hosts_backup,
|
||||
'gatus_from_services': self.from_services,
|
||||
}
|
||||
|
||||
default_alerts = [
|
||||
|
|
@ -17,7 +17,7 @@ class FilterModule(object):
|
|||
},
|
||||
]
|
||||
|
||||
def hosts_to_gatus(self, hosts):
|
||||
def from_hosts(self, hosts):
|
||||
result = []
|
||||
for host in hosts.values():
|
||||
result.append({
|
||||
|
|
@ -31,7 +31,7 @@ class FilterModule(object):
|
|||
})
|
||||
return result
|
||||
|
||||
def hosts_backup_to_gatus(self, hostvars):
|
||||
def from_hosts_backup(self, hostvars):
|
||||
result = []
|
||||
backup_alerts = []
|
||||
for a in self.default_alerts:
|
||||
|
|
@ -51,7 +51,7 @@ class FilterModule(object):
|
|||
})
|
||||
return result
|
||||
|
||||
def services_to_gatus(self, services):
|
||||
def from_services(self, services):
|
||||
result = []
|
||||
|
||||
default_conditions = [
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
- name: Generate systemd timer names
|
||||
ansible.builtin.set_fact:
|
||||
healthcheck_systemd_timers: "{{ healthcheck_svc.checks | list_prefix_suffix('healthcheck@', '.timer') }}"
|
||||
healthcheck_systemd_timers: "{{ healthcheck_svc.checks | utils_list_prefix_suffix('healthcheck@', '.timer') }}"
|
||||
|
||||
- name: Disable unused system timers
|
||||
ansible.builtin.systemd_service:
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'acmedns_to_lego': self.acmedns_to_lego,
|
||||
'lego_from_acmedns': self.from_acmedns,
|
||||
}
|
||||
|
||||
def acmedns_to_lego(self, acmedns_registered):
|
||||
def from_acmedns(self, acmedns_registered):
|
||||
result = {}
|
||||
for (key, value) in acmedns_registered.items():
|
||||
result[key] = {
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
- name: Create the acme-dns-accounts
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ (lego_config_path, 'acme-dns-accounts.json') | path_join }}"
|
||||
content: '{{ lego_acmedns_registered | acmedns_to_lego | to_json }}'
|
||||
content: '{{ lego_acmedns_registered | lego_from_acmedns | to_json }}'
|
||||
mode: "0644"
|
||||
- name: Copy the hook script
|
||||
ansible.builtin.copy:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
- name: Generate systemd timer names
|
||||
ansible.builtin.set_fact:
|
||||
lego_systemd_timers: "{{ lego_host_certificates | list_prefix_suffix('lego@', '.timer') }}"
|
||||
lego_systemd_timers: "{{ lego_host_certificates | utils_list_prefix_suffix('lego@', '.timer') }}"
|
||||
|
||||
- name: Disable unused system timers
|
||||
ansible.builtin.systemd_service:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ lgtm_stack_mimir_domain: mimir.serguzim.me
|
|||
lgtm_stack_alloy_domain: alloy.serguzim.me
|
||||
lgtm_stack_loki_domain: "{{ all_services | service_get_domain('loki') }}"
|
||||
|
||||
lgtm_stack_alloy_jobs: "{{ all_services | services_to_alloy() }}"
|
||||
lgtm_stack_alloy_jobs: "{{ all_services | lgtm_stack_services_to_alloy() }}"
|
||||
|
||||
lgtm_stack_grafana_secret_key: "{{ undef() }}"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ def transfer_optional_param(source, target, name, target_name=None):
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'services_to_alloy': self.services_to_alloy,
|
||||
'lgtm_stack_services_to_alloy': self.services_to_alloy,
|
||||
}
|
||||
|
||||
def services_to_alloy(self, services):
|
||||
11
playbooks/roles/postgresql/filter_plugins/postgresql.py
Normal file
11
playbooks/roles/postgresql/filter_plugins/postgresql.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'postgresql_restart_required': self.restart_required,
|
||||
}
|
||||
|
||||
def restart_required(self, results):
|
||||
for result in results:
|
||||
if result.get('restart_required') and result.get('changed'):
|
||||
return True
|
||||
return False
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
- name: Map exisiting/wanted caddy site configs
|
||||
ansible.builtin.set_fact:
|
||||
caddy_site_configs_have: "{{ find_result.files | map(attribute='path') }}"
|
||||
caddy_site_configs_want: "{{ host_services | services_names() | list_prefix_path_suffix(caddy_site_config_path, '.conf') }}"
|
||||
caddy_site_configs_want: "{{ host_services | services_names() | utils_list_prefix_path_suffix(caddy_site_config_path, '.conf') }}"
|
||||
|
||||
- name: Remove unwanted caddy site configs
|
||||
ansible.builtin.file:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue