ver 3
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
- name: Restart PostgreSQL
|
||||
service:
|
||||
name: postgresql
|
||||
state: restarted
|
||||
state: restarted
|
@ -5,8 +5,6 @@
|
||||
owner: postgres
|
||||
group: postgres
|
||||
mode: '0755'
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Perform database backup
|
||||
command: >
|
||||
@ -14,28 +12,22 @@
|
||||
become_user: postgres
|
||||
environment:
|
||||
PGPASSWORD: '{{ postgres_password }}'
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Daily cron full backup
|
||||
cron:
|
||||
name: 'PostgreSQL daily full backup'
|
||||
name: 'PostgreSQL daily full backup {{ postgres_user }}'
|
||||
user: postgres
|
||||
minute: '0'
|
||||
hour: '1'
|
||||
job: "pg_dump -U {{ postgres_user }} -F c {{ postgres_db }} > {{ backup_dir }}/full_db_backup_{{ postgres_db }}_$(date +\\%F-\\%H-%M).sql"
|
||||
environment:
|
||||
PGPASSWORD: '{{ postgres_password }}'
|
||||
tags:
|
||||
- backup
|
||||
|
||||
- name: Hourly cron incremental backup
|
||||
cron:
|
||||
name: 'PostgreSQL hourly incremental backup'
|
||||
name: 'PostgreSQL hourly incremental backup {{ postgres_user }}'
|
||||
user: postgres
|
||||
minute: '0'
|
||||
job: "pg_dump -U {{ postgres_user }} -F c --data-only --file=\"{{ backup_dir }}/incremental_db_backup_{{ postgres_db }}_$(date +\\%F-\\%H-%M).sql\" {{ postgres_db }}"
|
||||
environment:
|
||||
PGPASSWORD: '{{ postgres_password }}'
|
||||
tags:
|
||||
- backup
|
||||
PGPASSWORD: '{{ postgres_password }}'
|
@ -6,8 +6,6 @@
|
||||
group: postgres
|
||||
mode: '0644'
|
||||
notify: Restart PostgreSQL
|
||||
tags:
|
||||
- configure
|
||||
|
||||
- name: Configure pg_hba.conf with template
|
||||
template:
|
||||
@ -17,5 +15,3 @@
|
||||
group: postgres
|
||||
mode: '0644'
|
||||
notify: Restart PostgreSQL
|
||||
tags:
|
||||
- configure
|
||||
|
@ -4,14 +4,15 @@
|
||||
owner: '{{ postgres_user }}'
|
||||
encoding: UTF8
|
||||
state: present
|
||||
tags:
|
||||
- database
|
||||
|
||||
- name: Create contacts table in PostgreSQL
|
||||
community.postgresql.postgresql_query:
|
||||
db: '{{ postgres_db }}'
|
||||
query: 'CREATE TABLE IF NOT EXISTS contacts (id SERIAL PRIMARY KEY, name VARCHAR(100), phone_number VARCHAR(15));'
|
||||
query: |
|
||||
CREATE TABLE IF NOT EXISTS contacts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100),
|
||||
phone_number VARCHAR(15) UNIQUE
|
||||
);
|
||||
login_user: '{{ postgres_user }}'
|
||||
login_password: '{{ postgres_password }}'
|
||||
tags:
|
||||
- database
|
||||
login_password: '{{ postgres_password }}'
|
@ -2,13 +2,9 @@
|
||||
command: sudo -u postgres initdb -D /var/lib/pgsql/data
|
||||
args:
|
||||
creates: /var/lib/pgsql/data/PG_VERSION
|
||||
tags:
|
||||
- init
|
||||
|
||||
|
||||
- name: Systemctl start and enable PostgreSQL
|
||||
service:
|
||||
name: postgresql
|
||||
state: started
|
||||
enabled: true
|
||||
tags:
|
||||
- init
|
||||
|
11
roles/postgresql/tasks/insert_data.yml
Normal file
11
roles/postgresql/tasks/insert_data.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- name: Insert data into PostgreSQL database idempotently
|
||||
community.postgresql.postgresql_query:
|
||||
db: '{{ postgres_db }}'
|
||||
query: |
|
||||
INSERT INTO contacts (name, phone_number) VALUES
|
||||
('dima', '123123123'),
|
||||
('vlad', '8800525252'),
|
||||
('denis', '77777777')
|
||||
ON CONFLICT (phone_number) DO NOTHING;
|
||||
login_user: '{{ postgres_user }}'
|
||||
login_password: '{{ postgres_password }}'
|
@ -1,7 +1,31 @@
|
||||
- import_tasks: setup.yml
|
||||
tags:
|
||||
- setup
|
||||
|
||||
- import_tasks: initialize.yml
|
||||
tags:
|
||||
- init
|
||||
|
||||
- import_tasks: configure.yml
|
||||
tags:
|
||||
- configure
|
||||
|
||||
- import_tasks: users.yml
|
||||
tags:
|
||||
- users
|
||||
|
||||
- import_tasks: databases.yml
|
||||
tags:
|
||||
- database
|
||||
|
||||
- import_tasks: insert_data.yml
|
||||
tags:
|
||||
- insert
|
||||
|
||||
- import_tasks: open_firewall.yml
|
||||
- import_tasks: backup.yml
|
||||
tags:
|
||||
- firewall
|
||||
|
||||
- import_tasks: backup.yml
|
||||
tags:
|
||||
- backup
|
||||
|
@ -4,11 +4,7 @@
|
||||
permanent: true
|
||||
state: enabled
|
||||
become: true
|
||||
tags:
|
||||
- firewall
|
||||
|
||||
|
||||
- name: Reload firewall using command
|
||||
command: firewall-cmd --reload
|
||||
become: true
|
||||
tags:
|
||||
- firewall
|
||||
|
@ -4,12 +4,8 @@
|
||||
- postgresql-server
|
||||
- postgresql-contrib
|
||||
state: present
|
||||
tags:
|
||||
- setup
|
||||
|
||||
- name: Install python3-psycopg2
|
||||
zypper:
|
||||
name: python3-psycopg2
|
||||
state: present
|
||||
tags:
|
||||
- setup
|
||||
|
@ -2,6 +2,4 @@
|
||||
community.postgresql.postgresql_user:
|
||||
name: '{{ postgres_user }}'
|
||||
password: '{{ postgres_password }}'
|
||||
state: present
|
||||
tags:
|
||||
- users
|
||||
state: present
|
@ -5,7 +5,6 @@ postgres_hba_entries:
|
||||
- { type: 'host', database: 'all', user: 'all', address: '0.0.0.0/0', method: 'md5' }
|
||||
- { type: 'local', database: 'all', user: 'all', address: '', method: 'trust' }
|
||||
|
||||
backup_dir: "/var/lib/pgsql/backups"
|
||||
backup_dir: "/var/backups/postgresql"
|
||||
postgres_user: "postgres"
|
||||
postgres_password: "your_password"
|
||||
postgres_db: "your_database"
|
||||
postgres_db: "mydb"
|
||||
|
Reference in New Issue
Block a user