From 098135043b10b3dcfdf723fad41fbff42719cbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartal=20L=C3=A6arsson?= Date: Sat, 1 Mar 2025 22:02:02 +0000 Subject: [PATCH] remove redundant --- ansible/inventories/postgres.yml | 20 ------- ansible/playbooks/postgres.yml | 96 -------------------------------- 2 files changed, 116 deletions(-) delete mode 100644 ansible/inventories/postgres.yml delete mode 100644 ansible/playbooks/postgres.yml diff --git a/ansible/inventories/postgres.yml b/ansible/inventories/postgres.yml deleted file mode 100644 index eb62941..0000000 --- a/ansible/inventories/postgres.yml +++ /dev/null @@ -1,20 +0,0 @@ -[postgres_primary] -pg-primary ansible_host=10.203.146.218 - -[postgres_replicas] -pg-replica1 ansible_host=10.203.146.159 -pg-replica2 ansible_host=10.203.146.95 - -[postgres_lb] -pg-lb ansible_host=10.203.146.72 - -[postgres:children] -postgres_primary -postgres_replicas -postgres_lb - -[all:vars] -ansible_user=ubuntu -ansible_ssh_private_key_file=~/.ssh/id_rsa -ansible_python_interpreter=/usr/bin/python3 -ansible_ssh_common_args='-o StrictHostKeyChecking=no' diff --git a/ansible/playbooks/postgres.yml b/ansible/playbooks/postgres.yml deleted file mode 100644 index ec634b1..0000000 --- a/ansible/playbooks/postgres.yml +++ /dev/null @@ -1,96 +0,0 @@ ---- -- name: Configure PostgreSQL Primary - hosts: postgres_primary - become: true - tasks: - - name: Install PostgreSQL - apt: - name: postgresql - state: present - update_cache: yes - - - name: Ensure PostgreSQL is running - service: - name: postgresql - state: started - enabled: yes - - - name: Create test database - become: true - # Replace the direct become_user with a shell command that uses sudo - shell: | - sudo -u postgres psql -c "CREATE DATABASE testdb WITH OWNER = postgres ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE = template0;" - # Only run this if the database doesn't already exist - register: db_creation - changed_when: db_creation.rc == 0 - failed_when: db_creation.rc != 0 and "already exists" not in db_creation.stderr - # The following approach handles error gracefully if DB already exists - args: - executable: /bin/bash - -# Rest of the playbook remains the same -- name: Configure PostgreSQL Replicas - hosts: postgres_replicas - become: true - tasks: - - name: Install PostgreSQL - apt: - name: postgresql - state: present - update_cache: yes - - - name: Ensure PostgreSQL is running - service: - name: postgresql - state: started - enabled: yes - -- name: Configure Load Balancer - hosts: postgres_lb - become: true - tasks: - - name: Install HAProxy - apt: - name: haproxy - state: present - update_cache: yes - - - name: Create simple HAProxy configuration - copy: - dest: /etc/haproxy/haproxy.cfg - content: | - global - log /dev/log local0 - log /dev/log local1 notice - chroot /var/lib/haproxy - stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners - stats timeout 30s - user haproxy - group haproxy - daemon - - defaults - log global - mode tcp - option tcplog - option dontlognull - timeout connect 5000 - timeout client 50000 - timeout server 50000 - - frontend postgresql - bind *:5432 - mode tcp - default_backend postgresql_backends - - backend postgresql_backends - mode tcp - balance roundrobin - server primary {{ hostvars[groups['postgres_primary'][0]]['ansible_host'] }}:5432 check - backup: yes - - - name: Restart HAProxy - service: - name: haproxy - state: restarted - enabled: yes