Installation on RHEL8/CentOS8
GamerGun opened this issue · 4 comments
So did anyone actually get this working on RHEL8/CentOS8?
I mean, to me it seems it is not properly set-up for those, because;
- Using the initdb binary is deprecated, it should be postgresql-setup --initdb
- Custom PGDATA path needs to be set in systemd
- To install from the AppStream repo, one should run dnf install @PostgreSQL:9.6 (works with yum as well)
If not desired to be installed from AppStream it should become something like;
yum --disablerepo=rhel-8-for-x86_64-appstream-rpms install -y postgresql96-server postgresql96
Curious on what your findings are :)
Quick 'n dirty changes i made to initialize.yml:
- name: Ensure PostgreSQL database is initialized (Debian + Ubuntu)
command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
when:
- not pgdata_dir_version.stat.exists
- ansible_distribution | lower == 'debian' or ansible_distribution | lower == 'ubuntu'
become: true
become_user: "{{ postgresql_user }}"
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true
- name: Ensure PostgreSQL database is initialized (CentOS/RHEL-7)
command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
when:
- not pgdata_dir_version.stat.exists
- ansible_distribution | lower == 'redhat' or ansible_distribution | lower == 'centos'
- ansible_distribution_major_version == '7'
become: true
become_user: "{{ postgresql_user }}"
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true
- name: Make sure systemd PostgreSQL service.d directory exists
file:
path: /etc/systemd/system/postgresql-{{ postgresql_version }}.service.d
state: directory
owner: root
group: root
mode: '0755'
when:
- ansible_distribution | lower == 'redhat' or ansible_distribution | lower == 'centos'
- ansible_distribution_major_version == '8'
- name: Create systemd override.conf file for PostgreSQL (CentOS/RHEL-8)
ansible.builtin.template:
src: override.conf.j2
dest: /etc/systemd/system/postgresql-{{ postgresql_version }}.service.d/override.conf
owner: root
group: root
mode: '0755'
when:
- ansible_distribution | lower == 'redhat' or ansible_distribution | lower == 'centos'
- ansible_distribution_major_version == '8'
- name: Force systemd to re-execute itself (CentOS/RHEL-8)
ansible.builtin.systemd:
daemon_reexec: yes
when:
- ansible_distribution | lower == 'redhat' or ansible_distribution | lower == 'centos'
- ansible_distribution_major_version == '8'
- name: Ensure PostgreSQL database is initialized (CentOS/RHEL-8)
command: "/usr/bin/postgresql-setup --initdb"
when:
- not pgdata_dir_version.stat.exists
- ansible_distribution | lower == 'redhat' or ansible_distribution | lower == 'centos'
- ansible_distribution_major_version == '8'
become: true
become_user: "{{ postgresql_user }}"
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true
override.conf.j2 template
[Service]
Environment=PGDATA={{ postgresql_data_dir }}
My RHEL8 playbook:
---
- hosts: database
become: true
roles:
- role: ansible-role-base
- role: ansible-role-postgresql
postgresql_version: 9.6
postgresql_data_dir: /var/lib/pgsql/data
postgresql_config_path: /var/lib/pgsql/data
postgresql_daemon: postgresql.service
postgresql_packages:
- "@postgresql:9.6"
postgresql_databases:
- name: dbname
postgresql_users:
- name: dbuser
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
xxx
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read this blog post to see the reasons why I mark issues as stale.
At least for Postgres 10, I run this task before calling the role and it works fine:
- name: disable default Postgres module in Rhel 8
command: dnf module disable -y postgresql
register: __postgres_module_result
changed_when:
- '"Disabling modules" in __postgres_module_result.stdout'
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version | int >= 8
Based on comments in this thread: ansible/ansible#64852 (comment)
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.