Murat ÖZDEMİR f73504c0f2 Implement: Initial Ansible environment bootstrapping and core roles
This commit introduces the foundational Ansible playbooks, roles, and configurations for automated provisioning of both production and test environments.

Key capabilities include:
-   **Base System Setup:** Common packages, timezone, chrony, and hostname.
-   **Security Hardening:** SELinux disable, SSH configuration, `dnf-automatic`, `fail2ban`, `firewalld` setup, and `journald` log limits.
-   **Docker & Swarm:** Docker installation and configuration, Docker Swarm initialization/joining for managers and workers, overlay network creation, and node labeling.
-   **Storage:** Hetzner StorageBox integration using `davfs2`.
-   **Directory Structure:** Creation of application and database-specific directories.

This establishes a comprehensive, automated pipeline for infrastructure deployment and initial configuration.
2026-05-11 17:51:43 +03:00

75 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
- name: Check if Swarm is initialized
ansible.builtin.shell: docker info --format '{{.Swarm.LocalNodeState}}'
register: swarm_status
changed_when: false
# 1. İlk Manager'ın (Leader) başlatılması
- name: Initialize Docker Swarm (Leader)
ansible.builtin.shell: >
docker swarm init
--advertise-addr {{ private_ip }}
when:
- inventory_hostname == groups['app'][0]
- swarm_status.stdout != 'active'
register: swarm_init_result
# 2. Join Token'ların alınması (Sadece Leader üzerinden)
- name: Get Swarm Manager Join Token
ansible.builtin.shell: docker swarm join-token manager -q
register: manager_token
delegate_to: "{{ groups['app'][0] }}"
when: inventory_hostname == groups['app'][0]
changed_when: false
- name: Get Swarm Worker Join Token
ansible.builtin.shell: docker swarm join-token worker -q
register: worker_token
delegate_to: "{{ groups['app'][0] }}"
when: inventory_hostname == groups['app'][0]
changed_when: false
# 3. Diğer App sunucularının Manager olarak katılması (Prod HA için)
- name: Join Swarm as Manager
ansible.builtin.shell: >
docker swarm join
--token {{ hostvars[groups['app'][0]]['manager_token']['stdout'] }}
{{ swarm_manager_ip }}:2377
when:
- inventory_hostname in groups['app']
- inventory_hostname != groups['app'][0]
- swarm_status.stdout != 'active'
# 4. DB sunucularının Worker olarak katılması
- name: Join Swarm as Worker
ansible.builtin.shell: >
docker swarm join
--token {{ hostvars[groups['app'][0]]['worker_token']['stdout'] }}
{{ swarm_manager_ip }}:2377
when:
- inventory_hostname in groups['db']
- swarm_status.stdout != 'active'
# 5. Overlay Network oluşturulması (Sadece bir kez Leader üzerinden)
- name: Create iklimco-net overlay network
community.docker.docker_network:
name: iklimco-net
driver: overlay
attachable: yes
state: present
delegate_to: "{{ groups['app'][0] }}"
run_once: true
# 6. Node Etiketleri (Labels)
- name: Label App nodes (service)
ansible.builtin.shell: docker node update --label-add type=service {{ inventory_hostname }}
delegate_to: "{{ groups['app'][0] }}"
when: inventory_hostname in groups['app']
changed_when: false
- name: Label DB nodes (db)
ansible.builtin.shell: docker node update --label-add role=db {{ inventory_hostname }}
delegate_to: "{{ groups['app'][0] }}"
when: inventory_hostname in groups['db']
changed_when: false