# alflag-team/ansible architecture

> Architecture diagram of the GitHub repository alflag-team/ansible, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alflag-team/ansible
- Repository: https://github.com/alflag-team/ansible

## Overview

##### Main Components
- Inventory/Configuration Files – Highlight the central inventory (hosts.yml) and ansible.cfg that drive deployment.
- Variables & Vault – Represent “group_vars” directories that hold configuration variables and the encrypted “vault” files for sensitive information.
- Playbooks – Mark the playbook entry points (e.g., playbook.yml and various setup_*.yml files) that orchestrate the configurations.
- Roles – The repository is split by roles into several categories:
– “onp” directory: Contains role-specific playbooks for various service groups (e.g., admin.general, app.general, cache.redis, database, dns.unbound, log, web.general, etc.).
– “roles” directory: Includes reusable roles further broken down (e.g., common, middleware, etc.) for functionalities such as SSH configuration, LXC container setup, VM configuration, and middleware components (Docker, Caddy, kitsunebi, nginx, php, etc.).

##### Relationships and Interactions
- The playbook execution (via ansible-playbook command) pulls inventory from hosts.yml, uses variables from group_vars, and applies roles to target hosts.
- Roles are structured to be modular – for example, the “onp/database” directory invokes roles for setting up MySQL servers, while “onp/cache.redis” manages Redis deployments.
- Middleware roles act as the higher-level abtractions which wrap the application logic of underlying services (for example, roles/middleware/zabbix-server integrates with both MySQL and Nginx).

##### Architectural Patterns and Design Principles
- Modularity – The separation into numerous roles and directories demonstrates a modular design where each role manages one aspect of the system.
- Separation of Concerns – By having separate group_vars, inventory, and role directories for common settings and individual services, the design cleanly isolates configuration data from execution logic.
- Security by Design – The use of Ansible Vault for encrypting secrets is integral; it isolates sensitive configurations in encrypted “vault” files that are decrypted at runtime.
- Reusability – Common roles (like SSH and system settings) under “roles/common” are designed for reuse across different servers or groups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ansible Playbook Runner
    subgraph "Ansible Playbook Runner"
        A1["hosts.yml"]:::config
        A2["ansible.cfg"]:::config
    end

    %% Group Vars & Vault
    subgraph "Group Vars & Vault"
        GV1["group_vars/all"]:::vars
        GV2["group_vars/minecraftpanel"]:::vars
        GV3["group_vars/zabbix.general"]:::vars
    end

    %% Playbooks at Repository Root
    P1["setup_*.yml (Repo Root)"]:::playbook

    %% Service Roles (onp)
    subgraph "Service Roles (onp)"
        O1["onp/admin.general"]:::role
        O2["onp/app.general"]:::role
        O3["onp/cache.redis"]:::role
        O4["onp/database"]:::role
        O5["onp/dns.unbound"]:::role
        O6["onp/game.ptero-node"]:::role
        O7["onp/log"]:::role
        O8["onp/web.general"]:::role
        O9["onp/web.ptero-panel"]:::role
        O10["onp/zabbix.general"]:::role
    end

    %% Reusable Roles
    subgraph "Reusable Roles"
        subgraph "Common Roles"
            C1["roles/common"]:::common
            C2["roles/common/cloudflare-ssh"]:::common
            C3["roles/common/lxc"]:::common
            C4["roles/common/vm"]:::common
        end
        subgraph "Middleware Roles"
            M1["roles/middleware/nginx"]:::middleware
            M2["roles/middleware/mysql-server"]:::middleware
            M3["roles/middleware/redis-server"]:::middleware
            M4["roles/middleware/caddy"]:::middleware
            M5["roles/middleware/zabbix-server"]:::middleware
        end
    end

    %% Secrets Management
    S1["Secrets Management (secrets)"]:::secrets

    %% Connections from Playbook Runner to Group Vars
    A1 -->|"provides inventory"| GV1
    A2 -->|"provides config"| GV1

    %% Group Vars to Playbooks and Secrets Management
    GV1 -->|"supplies vars"| P1
    GV1 -->|"includes secrets"| S1

    %% Playbooks triggers roles execution
    P1 -->|"triggers"| O1
    P1 -->|"triggers"| O2
    P1 -->|"triggers"| O3
    P1 -->|"triggers"| O4
    P1 -->|"triggers"| O5
    P1 -->|"triggers"| O6
    P1 -->|"triggers"| O7
    P1 -->|"triggers"| O8
    P1 -->|"triggers"| O9
    P1 -->|"triggers"| O10
    P1 -->|"calls"| C1
    P1 -->|"calls"| M1

    %% Middleware dependency: Zabbix-server relies on MySQL and Nginx
    M5 -->|"dependsOn"| M2
    M5 -->|"dependsOn"| M1

    %% CLICK EVENTS
    click A1 "https://github.com/alflag-team/ansible/blob/master/hosts.yml"
    click A2 "https://github.com/alflag-team/ansible/blob/master/ansible.cfg"
    click GV1 "https://github.com/alflag-team/ansible/tree/master/group_vars/all"
    click GV2 "https://github.com/alflag-team/ansible/tree/master/group_vars/minecraftpanel"
    click GV3 "https://github.com/alflag-team/ansible/blob/master/group_vars/zabbix.general"
    click P1 "https://github.com/alflag-team/ansible/blob/master/setup_admin.general.yml"
    click O1 "https://github.com/alflag-team/ansible/blob/master/onp/admin.general/setup.yml"
    click O2 "https://github.com/alflag-team/ansible/blob/master/onp/app.general/setup.yml"
    click O3 "https://github.com/alflag-team/ansible/blob/master/onp/cache.redis/setup.yml"
    click O4 "https://github.com/alflag-team/ansible/blob/master/onp/database/setup.yml"
    click O5 "https://github.com/alflag-team/ansible/blob/master/onp/dns.unbound/setup.yml"
    click O6 "https://github.com/alflag-team/ansible/blob/master/onp/game.ptero-node/setup.yml"
    click O7 "https://github.com/alflag-team/ansible/blob/master/onp/log/setup.yml"
    click O8 "https://github.com/alflag-team/ansible/blob/master/onp/web.general/setup.yml"
    click O9 "https://github.com/alflag-team/ansible/blob/master/onp/web.ptero-panel/setup.yml"
    click O10 "https://github.com/alflag-team/ansible/blob/master/onp/zabbix.general/setup.yml"
    click C1 "https://github.com/alflag-team/ansible/tree/master/roles/common"
    click C2 "https://github.com/alflag-team/ansible/tree/master/roles/common/cloudflare-ssh"
    click C3 "https://github.com/alflag-team/ansible/tree/master/roles/common/lxc"
    click C4 "https://github.com/alflag-team/ansible/tree/master/roles/common/vm"
    click M1 "https://github.com/alflag-team/ansible/tree/master/roles/middleware/nginx"
    click M2 "https://github.com/alflag-team/ansible/tree/master/roles/middleware/mysql-server"
    click M3 "https://github.com/alflag-team/ansible/tree/master/roles/middleware/redis-server"
    click M4 "https://github.com/alflag-team/ansible/tree/master/roles/middleware/caddy"
    click M5 "https://github.com/alflag-team/ansible/tree/master/roles/middleware/zabbix-server"
    click S1 "https://github.com/alflag-team/ansible/tree/master/secrets"

    %% Styles
    classDef config fill:#fdd,stroke:#900,stroke-width:2px;
    classDef vars fill:#ddf,stroke:#009,stroke-width:2px;
    classDef playbook fill:#dfd,stroke:#090,stroke-width:2px;
    classDef role fill:#ffd,stroke:#990,stroke-width:2px;
    classDef common fill:#cff,stroke:#099,stroke-width:2px;
    classDef middleware fill:#fed,stroke:#d90,stroke-width:2px;
    classDef secrets fill:#fdd,stroke:#900,stroke-width:2px;
```
