mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-15 08:30:46 +02:00
Replaced redirects by origine to raise performance
This commit is contained in:
parent
1496f1de95
commit
f72ac30884
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
- name: Create Docker network for MariaDB
|
- name: Create Docker network for MariaDB
|
||||||
docker_network:
|
community.docker.docker_network:
|
||||||
name: "{{ mariadb_network_name }}"
|
name: "{{ mariadb_network_name }}"
|
||||||
state: present
|
state: present
|
||||||
ipam_config:
|
ipam_config:
|
||||||
- subnet: "{{ mariadb_subnet }}"
|
- subnet: "{{ mariadb_subnet }}"
|
||||||
|
|
||||||
- name: install MariaDB
|
- name: install MariaDB
|
||||||
docker_container:
|
community.docker.docker_container:
|
||||||
name: "{{ mariadb_name }}"
|
name: "{{ mariadb_name }}"
|
||||||
image: "{{ mariadb_image }}:{{ mariadb_version}}"
|
image: "{{ mariadb_image }}:{{ mariadb_version}}"
|
||||||
detach: yes
|
detach: yes
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- name: "Create database: {{ database_name }}"
|
- name: "Create database: {{ database_name }}"
|
||||||
mysql_db:
|
community.mysql.mysql_db:
|
||||||
name: "{{ database_name }}"
|
name: "{{ database_name }}"
|
||||||
state: present
|
state: present
|
||||||
login_user: root
|
login_user: root
|
||||||
@ -10,7 +10,7 @@
|
|||||||
collation: "{{ database_collation }}"
|
collation: "{{ database_collation }}"
|
||||||
|
|
||||||
- name: "Create database user: {{ database_username }}"
|
- name: "Create database user: {{ database_username }}"
|
||||||
mysql_user:
|
community.mysql.mysql_user:
|
||||||
name: "{{database_username}}"
|
name: "{{database_username}}"
|
||||||
password: "{{database_password}}"
|
password: "{{database_password}}"
|
||||||
host: "%"
|
host: "%"
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
when: not applications | get_app_conf(application_id, 'network.public', True) | bool
|
when: not applications | get_app_conf(application_id, 'network.public', True) | bool
|
||||||
|
|
||||||
- name: create docker network for LDAP, so that other applications can access it
|
- name: create docker network for LDAP, so that other applications can access it
|
||||||
docker_network:
|
community.docker.docker_network:
|
||||||
name: "{{ openldap_network }}"
|
name: "{{ openldap_network }}"
|
||||||
state: present
|
state: present
|
||||||
ipam_config:
|
ipam_config:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- name: Create Docker network for PostgreSQL
|
- name: Create Docker network for PostgreSQL
|
||||||
docker_network:
|
community.docker.docker_network:
|
||||||
name: "{{ postgres_network_name }}"
|
name: "{{ postgres_network_name }}"
|
||||||
state: present
|
state: present
|
||||||
ipam_config:
|
ipam_config:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
register: ssh_key
|
register: ssh_key
|
||||||
|
|
||||||
- name: Generate a SSH key for root if it does not exist
|
- name: Generate a SSH key for root if it does not exist
|
||||||
ansible.builtin.openssh_keypair:
|
community.crypto.openssh_keypair:
|
||||||
path: "/root/.ssh/id_rsa"
|
path: "/root/.ssh/id_rsa"
|
||||||
type: rsa
|
type: rsa
|
||||||
size: 4096
|
size: 4096
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
name: docker-compose
|
name: docker-compose
|
||||||
|
|
||||||
- name: Create Docker network for Collabora
|
- name: Create Docker network for Collabora
|
||||||
docker_network:
|
community.docker.docker_network:
|
||||||
name: svc-db-mariadb
|
name: svc-db-mariadb
|
||||||
state: present
|
state: present
|
||||||
ipam_config:
|
ipam_config:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: "stop and remove discourse container if it exist"
|
- name: "stop and remove discourse container if it exist"
|
||||||
docker_container:
|
community.docker.docker_container:
|
||||||
name: "{{ discourse_container }}"
|
name: "{{ discourse_container }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: container_action
|
register: container_action
|
||||||
|
71
tests/integration/test_no_module_redirections_in_logs.py
Normal file
71
tests/integration/test_no_module_redirections_in_logs.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# tests/integration/test_no_module_redirections_in_logs.py
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
import re
|
||||||
|
import unittest
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
REDIR_RE = re.compile(r"redirecting \(type: modules\)\s+(\S+)\s+to\s+(\S+)", re.IGNORECASE)
|
||||||
|
|
||||||
|
class ModuleRedirectionLogTest(unittest.TestCase):
|
||||||
|
"""
|
||||||
|
Fail if logs/*.log contains Ansible module redirections like:
|
||||||
|
'redirecting (type: modules) ansible.builtin.pacman to community.general.pacman'
|
||||||
|
Rationale: These lookups add overhead and clutter logs. Use fully-qualified
|
||||||
|
collection names directly in tasks to improve performance and clarity.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_no_module_redirections(self):
|
||||||
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||||
|
log_glob = os.path.join(project_root, "logs", "*.log")
|
||||||
|
files = sorted(glob.glob(log_glob))
|
||||||
|
|
||||||
|
if not files:
|
||||||
|
self.skipTest(f"No log files found at {log_glob}")
|
||||||
|
|
||||||
|
hits = []
|
||||||
|
mappings = defaultdict(int)
|
||||||
|
|
||||||
|
for path in files:
|
||||||
|
try:
|
||||||
|
with open(path, "r", encoding="utf-8", errors="replace") as fh:
|
||||||
|
for lineno, line in enumerate(fh, 1):
|
||||||
|
m = REDIR_RE.search(line)
|
||||||
|
if m:
|
||||||
|
src, dst = m.group(1), m.group(2)
|
||||||
|
hits.append((path, lineno, src, dst, line.strip()))
|
||||||
|
mappings[(src, dst)] += 1
|
||||||
|
except OSError as e:
|
||||||
|
self.fail(f"Cannot read log file {path}: {e}")
|
||||||
|
|
||||||
|
if hits:
|
||||||
|
# Build helpful failure message
|
||||||
|
suggestions = []
|
||||||
|
regex_hints = []
|
||||||
|
for (src, dst), count in sorted(mappings.items(), key=lambda x: (-x[1], x[0])):
|
||||||
|
suggestions.append(f"- Replace '{src}' with '{dst}' in your tasks ({count} occurrences).")
|
||||||
|
# Create VS Code regex for finding these in YAML
|
||||||
|
src_name = re.escape(src.split('.')[-1]) # only short module name
|
||||||
|
regex_hints.append(f"(?<!{re.escape(dst.rsplit('.',1)[0])}\\.){src_name}:")
|
||||||
|
|
||||||
|
examples = []
|
||||||
|
for i, (path, lineno, src, dst, text) in enumerate(hits[:10], 1):
|
||||||
|
examples.append(f"{i:02d}. {path}:{lineno}: {text}")
|
||||||
|
|
||||||
|
msg = (
|
||||||
|
f"Found {len(hits)} Ansible module redirections in logs/*.log.\n"
|
||||||
|
f"These slow down execution and clutter logs. "
|
||||||
|
f"Use fully-qualified module names to avoid runtime redirection.\n\n"
|
||||||
|
f"Suggested replacements:\n"
|
||||||
|
+ "\n".join(suggestions)
|
||||||
|
+ "\n\nExamples:\n"
|
||||||
|
+ "\n".join(examples)
|
||||||
|
+ "\n\nVS Code regex to find each occurrence in your code:\n"
|
||||||
|
+ "\n".join(f"- {hint}" for hint in sorted(set(regex_hints)))
|
||||||
|
+ "\n\nExample fix:\n"
|
||||||
|
f" # Instead of:\n"
|
||||||
|
f" pacman:\n"
|
||||||
|
f" # Use:\n"
|
||||||
|
f" community.general.pacman:\n"
|
||||||
|
)
|
||||||
|
self.fail(msg)
|
Loading…
x
Reference in New Issue
Block a user