-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8494c00
commit 1d8334e
Showing
2 changed files
with
57 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,67 @@ | ||
--- | ||
- name: Install Percona Distribution for PostgreSQL | ||
- name: Install Percona PostgreSQL on multiple OS | ||
hosts: all | ||
become: yes | ||
become: true | ||
vars_files: | ||
- ../vars.yml | ||
tasks: | ||
- name: Detect Operating System | ||
ansible.builtin.set_fact: | ||
is_debian: "{{ ansible_os_family == 'Debian' }}" | ||
is_redhat: "{{ ansible_os_family == 'RedHat' }}" | ||
|
||
- name: Install curl | ||
ansible.builtin.package: | ||
- name: Ensure curl is installed | ||
package: | ||
name: curl | ||
state: present | ||
|
||
# Debian/Ubuntu: Install Percona release package | ||
- name: Download Percona release package (Debian/Ubuntu) | ||
ansible.builtin.get_url: | ||
url: "{{ percona_repo_url }}/apt/{{ percona_release_package }}.{{ ansible_lsb.codename }}_all.deb" | ||
dest: "/tmp/{{ percona_release_package }}.{{ ansible_lsb.codename }}_all.deb" | ||
when: is_debian | ||
- name: Add Percona repository for DEB-based systems | ||
when: ansible_os_family | lower in os_family_deb | ||
block: | ||
- name: Download Percona release package | ||
get_url: | ||
url: "https://repo.percona.com/apt/percona-release_latest.{{ ansible_distribution_release }}_all.deb" | ||
dest: "/tmp/percona-release_latest_{{ ansible_distribution_release }}_all.deb" | ||
|
||
- name: Install Percona release package (Debian/Ubuntu) | ||
ansible.builtin.apt: | ||
deb: "/tmp/{{ percona_release_package }}.{{ ansible_lsb.codename }}_all.deb" | ||
state: present | ||
when: is_debian | ||
|
||
# RedHat/CentOS: Install Percona release package | ||
- name: Download Percona release package (RedHat/CentOS) | ||
ansible.builtin.get_url: | ||
url: "{{ percona_repo_url }}/yum/{{ percona_release_package }}.noarch.rpm" | ||
dest: "/tmp/{{ percona_release_package }}.noarch.rpm" | ||
when: is_redhat | ||
- name: Install Percona release package | ||
command: dpkg -i /tmp/percona-release_latest_{{ ansible_distribution_release }}_all.deb | ||
|
||
- name: Install Percona release package (RedHat/CentOS) | ||
ansible.builtin.yum: | ||
name: "/tmp/{{ percona_release_package }}.noarch.rpm" | ||
state: present | ||
when: is_redhat | ||
- name: Update apt cache | ||
apt: | ||
update_cache: true | ||
|
||
# Configure Percona repository | ||
- name: Configure Percona repository (RedHat/CentOS) | ||
ansible.builtin.command: | ||
cmd: percona-release setup ppg-{{ percona_version }} | ||
creates: "/etc/yum.repos.d/percona-ppg-{{ percona_version }}.repo" | ||
when: is_redhat | ||
- name: Enable Percona repository | ||
command: percona-release setup ppg-{{ percona_pg_version }} | ||
|
||
# Update package cache | ||
- name: Update package cache (Debian/Ubuntu) | ||
ansible.builtin.apt: | ||
update_cache: yes | ||
when: is_debian | ||
- name: Add Percona repository for RPM-based systems | ||
when: ansible_os_family | lower in os_family_rpm | ||
block: | ||
- name: Install Percona release package | ||
yum: | ||
name: "https://repo.percona.com/yum/percona-release-latest.noarch.rpm" | ||
state: present | ||
|
||
- name: Update package cache (RedHat/CentOS) | ||
ansible.builtin.yum: | ||
name: "*" | ||
state: latest | ||
when: is_redhat | ||
- name: Enable Percona repository | ||
command: percona-release setup ppg{{ percona_pg_version }} | ||
|
||
# Install Percona PostgreSQL packages | ||
- name: Install Percona PostgreSQL packages (Debian/Ubuntu) | ||
ansible.builtin.apt: | ||
name: "{{ debian_packages }}" | ||
- name: Install Percona PostgreSQL | ||
when: ansible_os_family | lower in os_family_deb + os_family_rpm | ||
package: | ||
name: | ||
- "percona-ppg-server-{{ percona_pg_version }}" | ||
- "percona-postgresql-{{ percona_pg_version }}-contrib" | ||
state: present | ||
when: is_debian | ||
|
||
- name: Install Percona PostgreSQL packages (RedHat/CentOS) | ||
ansible.builtin.yum: | ||
name: "{{ redhat_packages }}" | ||
state: present | ||
when: is_redhat | ||
- name: Initialize PostgreSQL database on RPM systems | ||
when: ansible_os_family | lower in os_family_rpm | ||
command: "/usr/pgsql-{{ percona_pg_version }}/bin/postgresql-{{ percona_pg_version }}-setup initdb" | ||
|
||
# Start and enable PostgreSQL service | ||
- name: Start and enable PostgreSQL service | ||
ansible.builtin.service: | ||
name: "{{ 'postgresql' if is_debian else 'postgresql-{{ percona_version }}' }}" | ||
- name: Start PostgreSQL service | ||
service: | ||
name: postgresql | ||
state: started | ||
enabled: yes | ||
enabled: true | ||
|
||
- name: Check PostgreSQL version | ||
command: "psql --version" | ||
register: postgres_version_output | ||
|
||
- name: Print PostgreSQL version | ||
debug: | ||
msg: "{{ postgres_version_output.stdout }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
percona_repo_url: "https://repo.percona.com" | ||
percona_release_package: "percona-release_latest" | ||
percona_version: "17" | ||
debian_packages: | ||
- "percona-ppg-server-17" | ||
redhat_packages: | ||
- "percona-ppg-server17" | ||
percona_pg_version: "17" # PostgreSQL versiyasi | ||
os_family_deb: | ||
- "debian" | ||
- "ubuntu" | ||
os_family_rpm: | ||
- "centos" | ||
- "rocky" | ||
- "oracle" | ||
- "redhat" |