62 lines
1.8 KiB
YAML
62 lines
1.8 KiB
YAML
---
|
|
- name: Install PostgreSQL on Ubuntu 20.04 LTS
|
|
hosts: localhost
|
|
become: yes
|
|
gather_facts: yes
|
|
tasks:
|
|
- name: Update apt cache
|
|
apt:
|
|
update_cache: yes
|
|
cache_valid_time: 3600
|
|
|
|
- name: Install necessary packages
|
|
apt:
|
|
name:
|
|
- python3-psycopg2
|
|
- postgresql
|
|
- postgresql-contrib
|
|
state: present
|
|
|
|
- name: Ensure PostgreSQL service is running
|
|
systemd:
|
|
name: postgresql
|
|
state: started
|
|
enabled: yes
|
|
|
|
- name: Update pg_hba.conf for local connections
|
|
lineinfile:
|
|
path: /etc/postgresql/12/main/pg_hba.conf
|
|
regexp: '^local\s+all\s+all\s+'
|
|
line: 'local all all trust'
|
|
state: present
|
|
notify: Restart PostgreSQL
|
|
|
|
- name: Configure PostgreSQL to accept connections from specified addresses
|
|
lineinfile:
|
|
path: /etc/postgresql/12/main/pg_hba.conf
|
|
regexp: '^host all all 192.168.1.0/24'
|
|
line: 'host all all 192.168.1.0/24 scram-sha-256'
|
|
state: present
|
|
notify: Restart PostgreSQL
|
|
|
|
- name: Configure PostgreSQL for better write performance
|
|
become: yes
|
|
lineinfile:
|
|
path: /etc/postgresql/12/main/postgresql.conf
|
|
regexp: "{{ item.regexp }}"
|
|
line: "{{ item.line }}"
|
|
loop:
|
|
- { regexp: '^shared_buffers', line: 'shared_buffers = 512MB' }
|
|
- { regexp: '^wal_buffers', line: 'wal_buffers = 16MB' }
|
|
- { regexp: '^checkpoint_completion_target', line: 'checkpoint_completion_target = 0.9' }
|
|
- { regexp: '^random_page_cost', line: 'random_page_cost = 1.0' }
|
|
- { regexp: '^effective_io_concurrency', line: 'effective_io_concurrency = 200' }
|
|
notify: Restart PostgreSQL
|
|
|
|
handlers:
|
|
- name: Restart PostgreSQL
|
|
systemd:
|
|
name: postgresql
|
|
state: restarted
|
|
|