diff --git a/README.md b/README.md index f180772..0e28eb0 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -Setup WAL-G for RHEL8 +Setup WAL-G + +Tested with OS: + - AlmaLinux 8/9 + - Debian 11 + - Ubuntu 20.04/22.04 diff --git a/defaults/main.yaml b/defaults/main.yaml index b632ba1..e024532 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,4 +1,5 @@ -wal_g_version: "2.0.1-3.el{{ ansible_distribution_major_version }}" +wal_g_version: "2.0.1" +wal_g_install_repo: true wal_g_pg: false wal_g_restore: false @@ -17,6 +18,11 @@ wal_g_backup_retention_schedule: "" wal_g_backup_retention_number: 7 wal_g_backup_permanent_schedule: "" +wal_g_postgresql_supported_versions: + - 13 + - 14 + - 15 + wal_g_default_config: # more options see https://github.com/wal-g/wal-g#configuration # AWS_ACCESS_KEY_ID: "secret-key" # AWS_SECRET_ACCESS_KEY: "access-key" diff --git a/tasks/backup_job.yaml b/tasks/backup_job.yaml index 955be31..6cff2a5 100644 --- a/tasks/backup_job.yaml +++ b/tasks/backup_job.yaml @@ -1,10 +1,3 @@ -- name: Install curl and jq - dnf: - name: - - jq - - curl - state: present - - name: Template backup script template: src: backup.sh.j2 diff --git a/tasks/backup_permanent_job.yaml b/tasks/backup_permanent_job.yaml index 90e44d5..d1e23cc 100644 --- a/tasks/backup_permanent_job.yaml +++ b/tasks/backup_permanent_job.yaml @@ -1,10 +1,3 @@ -- name: Install curl and jq - dnf: - name: - - jq - - curl - state: present - - name: Template backup permanent script template: src: backup-permanent.sh.j2 diff --git a/tasks/backup_retention_job.yaml b/tasks/backup_retention_job.yaml index 361150a..6ec98b5 100644 --- a/tasks/backup_retention_job.yaml +++ b/tasks/backup_retention_job.yaml @@ -1,10 +1,3 @@ -- name: Install curl and jq - dnf: - name: - - jq - - curl - state: present - - name: Template backup retention script template: src: backup-retention.sh.j2 diff --git a/tasks/pg.yaml b/tasks/pg.yaml index 218999c..02f12d5 100644 --- a/tasks/pg.yaml +++ b/tasks/pg.yaml @@ -1,16 +1,68 @@ --- -- name: "Install EPEL" - dnf: - name: "epel-release" - state: present +- 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 }} for PostgreSQL" - dnf: - name: "wal-g{{ ('-' ~ wal_g_version) | default('') }}" - state: installed - update_cache: yes - allow_downgrade: yes - tags: wal-g, wal_g, wal_g_install + - 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 }}" + apt: + 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" + apt: + name: + - curl + - jq + state: present + update_cache: yes - name: "Gather packages" package_facts: @@ -18,7 +70,7 @@ - name: "Set fact about PostgreSQL package" set_fact: - wal_g_postgresql_package: "{{ ansible_facts.packages | list | select('match', wal_g_pg_package_name_regex) | first }}" + wal_g_postgresql_package: "{{ ansible_facts.packages | list | select('match', wal_g_postgresql_package_name_regex) | first }}" - name: "Get PostgreSQL major version" set_fact: diff --git a/vars/Debian.yaml b/vars/Debian.yaml index cc638e7..b00a341 100644 --- a/vars/Debian.yaml +++ b/vars/Debian.yaml @@ -1,3 +1,13 @@ +wal_g_apt_repository: + - repo: deb [trusted=yes] https://mirror.0xace.cc/debian/custom/ default all + filename: mirror.0xace.cc + wal_g_pg_home_dir: "/var/lib/postgresql" wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ wal_g_pg_major_version }}/{{ wal_g_pg_cluster_name }}" wal_g_pg_cluster_name: "main" + +wal_g_postgresql_package_name_regex: 'postgresql-.[{{ wal_g_postgresql_supported_versions | join(",") }}]' + +wal_g_package_name: "wal-g" +wal_g_package: "{{ wal_g_package_name }}={{ wal_g_version }}-{{ wal_g_version_build }}" +wal_g_version_build: "4" diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml index 25448c5..51b3163 100644 --- a/vars/RedHat.yaml +++ b/vars/RedHat.yaml @@ -1,2 +1,14 @@ +wal_g_rpm_repository: + - name: "mirror.0xace.cc" + file: "mirror.0xace.cc" + description: "0xace.cc repository" + baseurl: "https://mirror.0xace.cc/rhel/$releasever/custom/" + gpgcheck: no + wal_g_pg_home_dir: "/var/lib/pgsql" wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ wal_g_pg_major_version }}/data" + +wal_g_postgresql_package_name_regex: 'postgresql.[{{ wal_g_postgresql_supported_versions | join(",") }}]-server' + +wal_g_package_name: "wal-g" +wal_g_package: "{{ wal_g_package_name }}-{{ wal_g_version }}"