-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW added postgresql installation ansible playbook
- Loading branch information
1 parent
d3126b9
commit 0d36923
Showing
6 changed files
with
123 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[postgresql_servers] | ||
server1 ansible_host=34.69.104.233 ansible_user=ismoilovdev | ||
server2 ansible_host=34.27.32.115 ansible_user=ismoilovdev | ||
server3 ansible_host=34.170.180.55 ansible_user=ismoilovdev |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
postgresql_version: 16 | ||
postgresql_password: "oasjofdjqpwe" | ||
listen_address: "*" # Postgresql.conf'da kiritiladi | ||
expose_address: "0.0.0.0/0" # pg_hba.conf'da kiritiladi |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: Install and configure PostgreSQL | ||
hosts: postgresql_servers | ||
become: yes | ||
vars_files: | ||
- main.yml | ||
|
||
tasks: | ||
- name: Detect operating system family | ||
set_fact: | ||
os_family: "{{ ansible_os_family }}" | ||
|
||
- name: Include Debian-based tasks if OS family is Debian | ||
include_tasks: tasks/install_postgresql_debian.yml | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Include Red Hat-based tasks if OS family is RedHat | ||
include_tasks: tasks/install_postgresql_redhat.yml | ||
when: ansible_os_family == "RedHat" | ||
|
||
- name: Configure PostgreSQL after installation | ||
include_tasks: tasks/configure_postgresql.yml |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: Set PostgreSQL user password using psql as root | ||
become: yes | ||
shell: su - postgres -c "psql -c \"ALTER USER postgres PASSWORD '{{ postgresql_password }}';\"" | ||
|
||
- name: Configure PostgreSQL to listen on all interfaces | ||
lineinfile: | ||
path: "/etc/postgresql/{{ postgresql_version }}/main/postgresql.conf" | ||
regexp: "^#listen_addresses =" | ||
line: "listen_addresses = '{{ listen_address }}'" | ||
state: present | ||
|
||
- name: Add pg_hba.conf rules | ||
lineinfile: | ||
path: "/etc/postgresql/{{ postgresql_version }}/main/pg_hba.conf" | ||
line: "host all all {{ expose_address }} md5" | ||
state: present | ||
|
||
- name: Restart PostgreSQL service | ||
systemd: | ||
name: "postgresql" | ||
state: restarted |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
- name: Install prerequisites on Debian-based systems | ||
apt: | ||
name: | ||
- curl | ||
- ca-certificates | ||
- postgresql-common | ||
state: present | ||
update_cache: yes | ||
|
||
# - name: Run PostgreSQL repository setup script | ||
# command: /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh | ||
|
||
- name: Create directory for PostgreSQL keys | ||
file: | ||
path: /usr/share/postgresql-common/pgdg | ||
state: directory | ||
mode: '0755' | ||
|
||
- name: Download PostgreSQL GPG key | ||
command: > | ||
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc | ||
- name: Add PostgreSQL repository | ||
shell: | | ||
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list | ||
- name: Update apt and install PostgreSQL (latest version) | ||
apt: | ||
name: postgresql | ||
state: present | ||
update_cache: yes | ||
|
||
- name: Enable and start PostgreSQL service | ||
systemd: | ||
name: postgresql | ||
enabled: yes | ||
state: started |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: Install PostgreSQL repository on Red Hat-based systems | ||
yum: | ||
name: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ ansible_distribution_major_version }}-x86_64/pgdg-redhat-repo-latest.noarch.rpm" | ||
state: present | ||
|
||
- name: Disable default PostgreSQL module on Red Hat 8 or higher | ||
when: ansible_distribution_major_version | int >= 8 | ||
shell: dnf -qy module disable postgresql | ||
|
||
- name: Install PostgreSQL server on Red Hat-based systems | ||
yum: | ||
name: "postgresql{{ postgresql_version }}-server" | ||
state: present | ||
|
||
- name: Initialize PostgreSQL database on Red Hat-based systems | ||
command: > | ||
/usr/pgsql-{{ postgresql_version }}/bin/postgresql-{{ postgresql_version }}-setup initdb | ||
when: ansible_distribution_major_version | int >= 7 | ||
|
||
- name: Enable and start PostgreSQL service on Red Hat-based systems | ||
systemd: | ||
name: "postgresql-{{ postgresql_version }}" | ||
enabled: yes | ||
state: started | ||
|
||
- name: Enable PostgreSQL service for RHEL/CentOS 6 | ||
when: ansible_distribution_major_version | int == 6 | ||
service: | ||
name: "postgresql-{{ postgresql_version }}" | ||
enabled: yes | ||
state: started |