Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: airgap-install for postgresql server #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions roles/postgresql/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ proxy_env:
no_proxy: "{{ no_proxy | default ('') }}"
NO_PROXY: "{{ no_proxy | default ('') }}"

postgresql_airgap_install: false
postgresql_install_from_file: false
postgresql_use_public_repo: yes
postgresql_public_repo_rpm_url: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ ansible_distribution_major_version }}-x86_64/pgdg-redhat-repo-latest.noarch.rpm"

Expand All @@ -29,6 +31,25 @@ postgresql_client_default_packages:
- libpq5
modern: # centos 8 and above
- python3-psycopg2

# database packages paths for air-gap install
# provide url path to package on satelite repo or path to local file
postgresql_default_packages_path:
common:
- https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/postgresql12-server-12.14-1PGDG.rhel7.x86_64.rpm
legacy: # centos 7 and below
- https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-x86_64/python2-psycopg2-2.8.6-1.rhel7.x86_64.rpm
modern: # centos 8 and above
- https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-x86_64/python3-psycopg2-2.8.6-1.rhel7.x86_64.rpm

# client packages paths for air-gap install
# provide url path to package on satelite repo or path to local file
postgresql_client_default_packages_path:
legacy: # centos 7 and below
- https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-x86_64/python2-psycopg2-2.8.6-1.rhel7.x86_64.rpm
- https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-x86_64/libpq5-15.2-42.1PGDG.rhel7.x86_64.rpm
modern: # centos 8 and above
- https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-7-x86_64/python3-psycopg2-2.8.6-1.rhel7.x86_64.rpm

postgresql_listen_addresses: "*"
postgresql_port: 5432
Expand Down
72 changes: 55 additions & 17 deletions roles/postgresql/tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,58 @@
# SPDX-License-Identifier: Apache-2.0

---
- name: Disable dnf module postgresql
command: dnf module disable postgresql -y
args:
warn: no
when: ansible_distribution_major_version | int > 7
register: dnf_result
changed_when: '"Disabling modules" in dnf_result.stdout'
notify: yum makecache

- import_tasks: public_repo.yml

- name: Install PostgreSQL packages
yum:
name: "{{ postgresql_default_packages['common'] + postgresql_default_packages[packages_version] }}"
state: present
vars:
packages_version: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('legacy','modern') }}"

- name: Install from public repo
block:
- name: Disable dnf module postgresql
command: dnf module disable postgresql -y
args:
warn: no
when: ansible_distribution_major_version | int > 7
register: dnf_result
changed_when: '"Disabling modules" in dnf_result.stdout'
notify: yum makecache

- import_tasks: public_repo.yml

- name: Install PostgreSQL packages
yum:
name: "{{ postgresql_default_packages['common'] + postgresql_default_packages[packages_version] }}"
state: present
vars:
packages_version: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('legacy','modern') }}"
when: postgresql_airgap_install == false

- name: Install from provided packages
block:

- name: Disable dnf module postgresql
command: dnf module disable postgresql -y
args:
warn: no
when: ansible_distribution_major_version | int > 7
register: dnf_result
changed_when: '"Disabling modules" in dnf_result.stdout'
notify: yum makecache

- name: Upload {{ item }}
copy:
src: files/{{ item }}
dest: "{{ binaries_upload_dir }}"
owner: root
group: root
mode: "644"
diff: false
vars:
packages_version: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('legacy','modern') }}"
loop: "{{ postgresql_default_packages['common'] + postgresql_default_packages[packages_version] }}"
when: postgresql_install_from_file == true

- name: Install PostgreSQL packages
yum:
name: "{{ postgresql_default_packages_path['common'] + postgresql_default_packages_path[packages_version] }}"
state: present
vars:
packages_version: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('legacy','modern') }}"

when: postgresql_airgap_install == true