diff --git a/ansible.cfg b/ansible.cfg index 4ae0c8c..ea0bfe0 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -2,3 +2,4 @@ inventory = inventory.yml roles_path = ./roles force_color = true +interpreter_python = /usr/bin/python3 diff --git a/inventory.yml b/inventory.yml index 215250f..590be8f 100644 --- a/inventory.yml +++ b/inventory.yml @@ -1,6 +1,4 @@ all: - children: - postgres_servers: - hosts: - 192.168.0.71: - ansible_user: ansible \ No newline at end of file + hosts: + 192.168.0.71: + ansible_user: ansible \ No newline at end of file diff --git a/roles/postgresql/tasks/configure.yml b/roles/postgresql/tasks/configure.yml index c015e8d..9cd61ac 100644 --- a/roles/postgresql/tasks/configure.yml +++ b/roles/postgresql/tasks/configure.yml @@ -1,4 +1,4 @@ -- name: Configure postgresql.conf with template +- name: Configure postgresql.conf template: src: postgresql.conf.j2 dest: /var/lib/pgsql/data/postgresql.conf @@ -7,7 +7,7 @@ mode: '0644' notify: Restart PostgreSQL -- name: Configure pg_hba.conf with template +- name: Configure pg_hba.conf template: src: pg_hba.conf.j2 dest: /var/lib/pgsql/data/pg_hba.conf diff --git a/roles/postgresql/tasks/databases.yml b/roles/postgresql/tasks/databases.yml index 66dabdd..ac5cf48 100644 --- a/roles/postgresql/tasks/databases.yml +++ b/roles/postgresql/tasks/databases.yml @@ -5,7 +5,7 @@ encoding: UTF8 state: present -- name: Create contacts table in PostgreSQL +- name: Create contacts table community.postgresql.postgresql_query: db: '{{ postgres_db }}' query: | diff --git a/roles/postgresql/tasks/insert_data.yml b/roles/postgresql/tasks/insert_data.yml index 151f687..4f7dcd5 100644 --- a/roles/postgresql/tasks/insert_data.yml +++ b/roles/postgresql/tasks/insert_data.yml @@ -1,4 +1,4 @@ -- name: Insert data into PostgreSQL database idempotently +- name: Insert data into PostgreSQL database community.postgresql.postgresql_query: db: '{{ postgres_db }}' query: | diff --git a/roles/postgresql/tasks/open_firewall.yml b/roles/postgresql/tasks/open_firewall.yml index 99ff9ed..2c084af 100644 --- a/roles/postgresql/tasks/open_firewall.yml +++ b/roles/postgresql/tasks/open_firewall.yml @@ -4,7 +4,9 @@ permanent: true state: enabled become: true - -- name: Reload firewall using command - command: firewall-cmd --reload + +- name: Reload firewalld + systemd: + name: firewalld + state: reloaded become: true diff --git a/roles/postgresql/templates/postgresql.conf.j2 b/roles/postgresql/templates/postgresql.conf.j2 index 7013fde..7bff891 100644 --- a/roles/postgresql/templates/postgresql.conf.j2 +++ b/roles/postgresql/templates/postgresql.conf.j2 @@ -1,12 +1,11 @@ -listen_addresses = '{{ postgres_listen_addresses | default("*") }}' +listen_addresses = '{{ postgres_listen_addresses }}' -port = {{ postgres_port | default(5432) }} +port = {{ postgres_port }} - -max_connections = {{ postgres_max_connections | default(100) }} -shared_buffers = {{ postgres_shared_buffers | default("128MB") }} -effective_cache_size = {{ postgres_effective_cache_size | default("4GB") }} -maintenance_work_mem = {{ postgres_maintenance_work_mem | default("64MB") }} -checkpoint_completion_target = {{ postgres_checkpoint_completion_target | default(0.7) }} -wal_buffers = {{ postgres_wal_buffers | default("16MB") }} -default_statistics_target = {{ postgres_default_statistics_target | default(100) }} \ No newline at end of file +max_connections = {{ postgres_max_connections }} +shared_buffers = {{ postgres_shared_buffers }} +effective_cache_size = {{ postgres_effective_cache_size }} +maintenance_work_mem = {{ postgres_maintenance_work_mem }} +checkpoint_completion_target = {{ postgres_checkpoint_completion_target }} +wal_buffers = {{ postgres_wal_buffers }} +default_statistics_target = {{ postgres_default_statistics_target }} diff --git a/roles/postgresql/vars/main.yml b/roles/postgresql/vars/main.yml index 2dd04d2..c76a487 100644 --- a/roles/postgresql/vars/main.yml +++ b/roles/postgresql/vars/main.yml @@ -8,3 +8,11 @@ postgres_hba_entries: backup_dir: "/var/backups/postgresql" postgres_user: "postgres" postgres_db: "mydb" + +postgres_max_connections: 100 +postgres_shared_buffers: '128MB' +postgres_effective_cache_size: '4GB' +postgres_maintenance_work_mem: '64MB' +postgres_checkpoint_completion_target: 0.7 +postgres_wal_buffers: '16MB' +postgres_default_statistics_target: 100 \ No newline at end of file