mirror of
https://gitea.0xace.cc/ansible-galaxy/wal-g-pg.git
synced 2025-06-28 21:23:08 +00:00
first commit
This commit is contained in:
22
tasks/backup_job.yaml
Normal file
22
tasks/backup_job.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: Template backup script
|
||||
template:
|
||||
src: backup.sh.j2
|
||||
dest: "{{ wal_g_pg_home_dir }}/backup.sh"
|
||||
mode: 0755
|
||||
owner: "{{ wal_g_pg_backup_owner }}"
|
||||
group: "{{ wal_g_pg_backup_group }}"
|
||||
|
||||
- name: Template systemd backup service
|
||||
template:
|
||||
src: backup.service.j2
|
||||
dest: /etc/systemd/system/backup.service
|
||||
notify: Daemon reload backup service
|
||||
register: backup_service
|
||||
|
||||
- name: Reload systemd backup service
|
||||
systemd:
|
||||
name: backup.service
|
||||
enabled: no
|
||||
masked: no
|
||||
daemon_reload: yes
|
||||
when: not backup_service.changed
|
15
tasks/backup_job_timer.yaml
Normal file
15
tasks/backup_job_timer.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
- name: Template systemd backup timer
|
||||
template:
|
||||
src: backup.timer.j2
|
||||
dest: /etc/systemd/system/backup.timer
|
||||
notify: Restart backup timer
|
||||
register: backup_timer
|
||||
|
||||
- name: Enable and start systemd backup timer
|
||||
systemd:
|
||||
name: backup.timer
|
||||
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
|
||||
masked: no
|
||||
state: started
|
||||
daemon_reload: yes
|
||||
when: not backup_timer.changed
|
22
tasks/backup_permanent_job.yaml
Normal file
22
tasks/backup_permanent_job.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: Template backup permanent script
|
||||
template:
|
||||
src: backup-permanent.sh.j2
|
||||
dest: "{{ wal_g_pg_home_dir }}/backup-permanent.sh"
|
||||
mode: 0755
|
||||
owner: "{{ wal_g_pg_backup_owner }}"
|
||||
group: "{{ wal_g_pg_backup_group }}"
|
||||
|
||||
- name: Template systemd backup permanent service
|
||||
template:
|
||||
src: backup-permanent.service.j2
|
||||
dest: /etc/systemd/system/backup-permanent.service
|
||||
notify: Daemon reload backup permanent service
|
||||
register: backup_permanent_service
|
||||
|
||||
- name: Reload systemd backup permanent service
|
||||
systemd:
|
||||
name: backup-permanent.service
|
||||
enabled: no
|
||||
masked: no
|
||||
daemon_reload: yes
|
||||
when: not backup_permanent_service.changed
|
15
tasks/backup_permanent_job_timer.yaml
Normal file
15
tasks/backup_permanent_job_timer.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
- name: Template systemd backup permanent timer
|
||||
template:
|
||||
src: backup-permanent.timer.j2
|
||||
dest: /etc/systemd/system/backup-permanent.timer
|
||||
notify: Restart backup permanent timer
|
||||
register: backup_permanent_timer
|
||||
|
||||
- name: Enable and start systemd backup permanent timer
|
||||
systemd:
|
||||
name: backup-permanent.timer
|
||||
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
|
||||
masked: no
|
||||
state: started
|
||||
daemon_reload: yes
|
||||
when: not backup_permanent_timer.changed
|
23
tasks/backup_retention_job.yaml
Normal file
23
tasks/backup_retention_job.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
- name: Template backup retention script
|
||||
template:
|
||||
src: backup-retention.sh.j2
|
||||
dest: "{{ wal_g_pg_home_dir }}/backup-retention.sh"
|
||||
mode: 0755
|
||||
owner: "{{ wal_g_pg_backup_owner }}"
|
||||
group: "{{ wal_g_pg_backup_group }}"
|
||||
|
||||
- name: Template systemd backup retention service
|
||||
template:
|
||||
src: backup-retention.service.j2
|
||||
dest: /etc/systemd/system/backup-retention.service
|
||||
notify: Daemon reload backup retention service
|
||||
register: backup_retention_service
|
||||
|
||||
- name: Reload systemd backup retention service
|
||||
systemd:
|
||||
name: backup-retention.service
|
||||
enabled: no
|
||||
masked: no
|
||||
daemon_reload: yes
|
||||
when: not backup_retention_service.changed
|
||||
|
15
tasks/backup_retention_job_timer.yaml
Normal file
15
tasks/backup_retention_job_timer.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
- name: Template systemd backup retention timer
|
||||
template:
|
||||
src: backup-retention.timer.j2
|
||||
dest: /etc/systemd/system/backup-retention.timer
|
||||
notify: Restart backup retention timer
|
||||
register: backup_retention_timer
|
||||
|
||||
- name: Enable and start systemd backup retention timer
|
||||
systemd:
|
||||
name: backup-retention.timer
|
||||
enabled: "{{ 'yes' if wal_g_backup_enable else 'no' }}"
|
||||
masked: no
|
||||
state: started
|
||||
daemon_reload: yes
|
||||
when: not backup_retention_timer.changed
|
56
tasks/main.yml
Normal file
56
tasks/main.yml
Normal file
@ -0,0 +1,56 @@
|
||||
---
|
||||
- name: Load a variable file based on the OS type
|
||||
include_vars: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- "{{ ansible_facts['distribution'] }}.yaml"
|
||||
- "{{ ansible_facts['os_family'] }}.yaml"
|
||||
paths:
|
||||
- "vars"
|
||||
tags: wal_g_vars
|
||||
|
||||
- name: Set facts about needed vars
|
||||
set_fact:
|
||||
wal_g_pg_home_dir: "{{ wal_g_pg_home_dir }}"
|
||||
wal_g_pg_data_dir: "{{ wal_g_pg_data_dir }}"
|
||||
|
||||
- name: "Include install WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: pg.yaml
|
||||
when: wal_g_pg
|
||||
|
||||
- name: "Include backup job with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_job.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
|
||||
- name: "Include backup job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_job_timer.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
- wal_g_backup_schedule is defined
|
||||
- wal_g_backup_schedule | length > 0
|
||||
|
||||
- name: "Include backup retention job with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_retention_job.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
|
||||
- name: "Include backup retention job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_retention_job_timer.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
- wal_g_backup_retention_schedule is defined
|
||||
- wal_g_backup_retention_schedule | length > 0
|
||||
|
||||
- name: "Include permanent backup job with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_permanent_job.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
|
||||
- name: "Include permanent backup job timer with WAL-G {{ wal_g_version }} for PostgreSQL"
|
||||
include_tasks: backup_permanent_job_timer.yaml
|
||||
when:
|
||||
- wal_g_pg
|
||||
- wal_g_backup_permanent_schedule is defined
|
||||
- wal_g_backup_permanent_schedule | length > 0
|
111
tasks/pg.yaml
Normal file
111
tasks/pg.yaml
Normal file
@ -0,0 +1,111 @@
|
||||
---
|
||||
- name: RHEL based distros
|
||||
when: ansible_os_family == "RedHat"
|
||||
block:
|
||||
- name: Install WAL-G repository
|
||||
ansible.builtin.yum_repository:
|
||||
name: "{{ item.name }}"
|
||||
description: "{{ item.description }}"
|
||||
file: "{{ item.file }}"
|
||||
baseurl: "{{ item.baseurl }}"
|
||||
gpgcheck: "{{ item.gpgcheck | default('no') }}"
|
||||
enabled: "{{ item.enabled | default('yes') }}"
|
||||
repo_gpgcheck: "{{ item.repo_gpgcheck | default('no') }}"
|
||||
gpgkey: "{{ item.gpgkey | default(omit) }}"
|
||||
loop: "{{ wal_g_rpm_repository }}"
|
||||
when: wal_g_install_repo
|
||||
|
||||
- name: "Install WAL-G {{ wal_g_version }}"
|
||||
dnf:
|
||||
name: "{{ wal_g_package }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
allow_downgrade: yes
|
||||
tags: wal-g, wal_g, wal_g_install
|
||||
|
||||
- name: "Install curl and jq"
|
||||
dnf:
|
||||
name:
|
||||
- curl
|
||||
- jq
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Debian based distros
|
||||
when: ansible_os_family == "Debian"
|
||||
block:
|
||||
- name: Install apt-transport-https
|
||||
apt:
|
||||
name: apt-transport-https
|
||||
state: present
|
||||
|
||||
- name: Add WAL-G repository
|
||||
ansible.builtin.apt_repository:
|
||||
repo: "{{ item.repo }}"
|
||||
state: present
|
||||
filename: "{{ item.filename }}"
|
||||
update_cache: yes
|
||||
loop: "{{ wal_g_apt_repository }}"
|
||||
when: wal_g_install_repo
|
||||
|
||||
- name: "Install WAL-G {{ wal_g_version }} and deps"
|
||||
apt:
|
||||
name:
|
||||
- "{{ wal_g_package }}"
|
||||
- libsodium23
|
||||
- liblzo2-2
|
||||
state: present
|
||||
update_cache: yes
|
||||
allow_downgrade: yes
|
||||
tags: wal-g, wal_g, wal_g_install
|
||||
|
||||
- name: "Install curl and jq"
|
||||
apt:
|
||||
name:
|
||||
- curl
|
||||
- jq
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: "Gather packages"
|
||||
package_facts:
|
||||
manager: auto
|
||||
|
||||
- name: "Set fact about PostgreSQL package"
|
||||
set_fact:
|
||||
wal_g_postgresql_package: "{{ ansible_facts.packages | list | select('match', wal_g_postgresql_package_name_regex) | first }}"
|
||||
|
||||
- name: "Get PostgreSQL major version"
|
||||
set_fact:
|
||||
wal_g_pg_major_version: "{{ ansible_facts.packages[wal_g_postgresql_package][0]['version'] | split('.') | first }}"
|
||||
|
||||
- name: Create wal-g config
|
||||
when: wal_g_config is defined
|
||||
block:
|
||||
- name: Merge user options for WAL-G part of config
|
||||
set_fact:
|
||||
wal_g_combined_config: "{{ wal_g_default_config | combine(wal_g_config|default({}), recursive=true) }}"
|
||||
|
||||
- name: "Generate conf file walg.json"
|
||||
copy:
|
||||
content: "{{ wal_g_combined_config | to_nice_json }}"
|
||||
dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_config_name }}"
|
||||
owner: "{{ wal_g_pg_config_owner }}"
|
||||
group: "{{ wal_g_pg_config_group }}"
|
||||
mode: 0644
|
||||
tags: wal-g, wal_g, wal_g_conf
|
||||
|
||||
- name: Create wal-g restore config
|
||||
when: wal_g_restore_config is defined
|
||||
block:
|
||||
- name: Merge user options for WAL-G part of restore config
|
||||
set_fact:
|
||||
wal_g_restore_combined_config: "{{ wal_g_default_restore_config | combine(wal_g_restore_config|default({}), recursive=true) }}"
|
||||
|
||||
- name: "Generate conf file walg-restore.json"
|
||||
copy:
|
||||
content: "{{ wal_g_restore_combined_config | to_nice_json }}"
|
||||
dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_restore_config_name }}"
|
||||
owner: "{{ wal_g_pg_config_owner }}"
|
||||
group: "{{ wal_g_pg_config_group }}"
|
||||
mode: 0644
|
Reference in New Issue
Block a user