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

tests: setup five pg versions for testing #290

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: copy control file for dummy ext
copy:
src: dummy.control
dest: /usr/share/postgresql/{{ pg_ver }}/extension/dummy.control
mode: '0444'

- name: copy version files for dummy ext
copy:
src: '{{ item }}'
dest: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
mode: '0444'
with_items:
- dummy--0.sql
- dummy--1.0.sql
- dummy--2.0.sql
- dummy--3.0.sql

- name: add update paths
file:
path: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
mode: '0444'
state: touch
with_items:
- dummy--0--1.0.sql
- dummy--1.0--2.0.sql
- dummy--2.0--3.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: disable PG module (RH8+)
command: dnf -y module disable postgresql
when:
- ansible_facts.os_family == 'RedHat'
- ansible_facts.distribution_major_version is version('8', '>=')

- name: install dependencies for postgresql test
package:
name: '{{ postgresql_package_item }}'
state: present
with_nested: '{{ postgresql_packages }}'
loop_control:
loop_var: postgresql_package_item
218 changes: 110 additions & 108 deletions tests/integration/targets/setup_postgresql_db/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
paths:
- '{{ role_path }}/vars'

- name: Make sure the dbus service is enabled under systemd
shell: systemctl enable dbus || systemctl enable dbus-broker
ignore_errors: yes
when: ansible_service_mgr == 'systemd' and ansible_distribution == 'Fedora'

- name: Make sure the dbus service is started under systemd
systemd:
name: dbus
state: started
- block:
- name: Make sure the dbus service is enabled under systemd
shell: systemctl enable dbus || systemctl enable dbus-broker
ignore_errors: yes
- name: Make sure the dbus service is started under systemd
systemd:
name: dbus
state: started
when: ansible_service_mgr == 'systemd' and ansible_distribution == 'Fedora'

- name: Kill all postgres processes
Expand All @@ -46,72 +45,62 @@
service: name={{ postgresql_service }} state=stopped
ignore_errors: true

- name: remove old db (RedHat)
file:
path: '{{ pg_dir }}'
state: absent
ignore_errors: true
when: ansible_os_family == "RedHat"

- name: remove old db config and files (debian)
- name: remove old db config and files
file:
path: '{{ loop_item }}'
state: absent
ignore_errors: true
when: ansible_os_family == "Debian"
loop:
- /etc/postgresql
- /var/lib/postgresql
loop_control:
loop_var: loop_item

#
# Install PostgreSQL 14 on Ubuntu 20.04
- name: Install wget
package:
name: wget
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'

- name: Add a repository
shell: echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'

- name: Add a repository
shell: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'
## Install PGDG repo on Ubuntu
- block:
- name: Install wget
package:
name: wget
- name: Add a repository
shell: echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
- name: Add a repository
shell: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- name: Add a repository
shell: apt -y update
- name: Install locale needed
shell: 'locale-gen {{ item }}'
loop:
- es_ES
- pt_BR
- name: Update locale
shell: 'update-locale'
when: ansible_facts.distribution == 'Ubuntu'
##
#

#
## Install PGDG repo on RedHat family
- name: Add a repository
shell: apt -y update
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'
shell: 'yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ansible_facts.distribution_major_version}}-x86_64/pgdg-redhat-repo-latest.noarch.rpm'
when: ansible_facts.os_family == 'RedHat'

- name: Install locale needed
shell: 'locale-gen {{ item }}'
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'
loop:
- es_ES
- pt_BR

- name: Update locale
shell: 'update-locale'
when: ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version == '20'
##
#

- name: install dependencies for postgresql test
package:
name: '{{ postgresql_package_item }}'
state: present
with_items: '{{ postgresql_packages }}'
- include_tasks: install_deps.yml
with_sequence: start=10 count=5
loop_control:
loop_var: postgresql_package_item
loop_var: pg_ver

- name: Initialize postgres (RedHat systemd)
command: postgresql-setup initdb
when: ansible_os_family == "RedHat" and ansible_service_mgr == "systemd"

- name: Initialize postgres (RedHat sysv)
command: /sbin/service postgresql initdb
when: ansible_os_family == "RedHat" and ansible_service_mgr != "systemd"
command: 'postgresql-{{ pg_ver }}-setup initdb'
when:
- ansible_service_mgr == "systemd"
- ansible_os_family == "RedHat"
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver

- name: Initialize postgres (Debian)
shell: . /usr/share/postgresql-common/maintscripts-functions && set_system_locale && /usr/bin/pg_createcluster -u postgres {{ pg_ver }} main
Expand All @@ -126,6 +115,9 @@
owner: '{{ pg_user }}'
group: '{{ pg_group }}'
mode: '0644'
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver

- name: Generate locales (Debian)
locale_gen:
Expand All @@ -145,7 +137,6 @@
- glibc-all-langpacks
state: present
when: ansible_distribution_major_version is version('8', '>=')

- name: Check if locales need to be generated (RedHat)
shell: localedef --list-archive | grep -a -q '^{{ locale }}$'
register: locale_present
Expand All @@ -155,7 +146,6 @@
- pt_BR
loop_control:
loop_var: locale

- block:
- name: Reinstall internationalization files
command: yum -y reinstall glibc-common
Expand All @@ -165,7 +155,6 @@
name: glibc-common
state: present
when: locale_present is failed

- name: Generate locale (RedHat)
command: localedef -f ISO-8859-1 -i {{ item.locale }} {{ item.locale }}
when: item is failed
Expand All @@ -181,72 +170,85 @@
- glibc-langpack-pt
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('24', '>=')

- name: start postgresql service
service: name={{ postgresql_service }} state=started
- name: Correct the port
lineinfile:
path: '{{pg_dir}}/postgresql.conf'
regexp: '^port '
insertafter: '^#port '
line: 'port = 54{{ pg_ver }}'
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver

- name: start postgresql service (RedHat)
become_user: '{{ pg_user }}'
become: true
command: '/usr/pgsql-{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} start'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'RedHat'
loop_control:
loop_var: pg_ver

- name: start postgresql service (Debian)
become_user: '{{ pg_user }}'
become: true
command: '/usr/lib/postgresql/{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} start'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'Debian'
loop_control:
loop_var: pg_ver

- name: Pause between start and stop
pause:
seconds: 5

- name: Kill all postgres processes
shell: 'pkill -u {{ pg_user }}'
become: yes
when: ansible_facts.distribution == 'CentOS' and ansible_facts.distribution_major_version == '8'
ignore_errors: yes
register: terminate
- name: stop postgresql service (RedHat)
become_user: '{{ pg_user }}'
become: true
command: '/usr/pgsql-{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} stop'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'RedHat'
loop_control:
loop_var: pg_ver

- name: Stop postgresql service
service: name={{ postgresql_service }} state=stopped
when: terminate is not succeeded
- name: stop postgresql service (Debian)
become_user: '{{ pg_user }}'
become: true
command: '/usr/lib/postgresql/{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} stop'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'Debian'
loop_control:
loop_var: pg_ver

- name: Pause between stop and start
pause:
seconds: 5

- name: Start postgresql service
service: name={{ postgresql_service }} state=started

- name: copy control file for dummy ext
copy:
src: dummy.control
dest: /usr/share/postgresql/{{ pg_ver }}/extension/dummy.control
mode: '0444'
when: ansible_os_family == 'Debian'

- name: copy version files for dummy ext
copy:
src: '{{ item }}'
dest: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
mode: '0444'
with_items:
- dummy--0.sql
- dummy--1.0.sql
- dummy--2.0.sql
- dummy--3.0.sql
when: ansible_os_family == 'Debian'

- name: add update paths
file:
path: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
mode: '0444'
state: touch
with_items:
- dummy--0--1.0.sql
- dummy--1.0--2.0.sql
- dummy--2.0--3.0.sql
when: ansible_os_family == 'Debian'
- name: start postgresql service (RedHat)
become_user: '{{ pg_user }}'
become: true
command: '/usr/pgsql-{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} start'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'RedHat'
loop_control:
loop_var: pg_ver

- name: Get PostgreSQL version
- name: start postgresql service (Debian)
become_user: '{{ pg_user }}'
become: true
shell: echo 'SHOW SERVER_VERSION' | psql --tuples-only --no-align --dbname postgres
register: postgres_version_resp
command: '/usr/lib/postgresql/{{ pg_ver }}/bin/pg_ctl -D {{pg_dir}} start'
with_sequence: start=10 count=5
when: ansible_facts.os_family == 'Debian'
loop_control:
loop_var: pg_ver

- name: Print PostgreSQL server version
debug:
msg: '{{ postgres_version_resp.stdout }}'
- name: set up dummy extension (Debian)
include_tasks: dummy_ext.yml
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver
when: ansible_os_family == 'Debian'

- import_tasks: ssl.yml
when:
- ansible_os_family == 'Debian'
- postgres_version_resp.stdout is version('9.4', '>=')
19 changes: 15 additions & 4 deletions tests/integration/targets/setup_postgresql_db/tasks/ssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,20 @@
db: postgres
name: ssl
value: true
port: '54{{ pg_ver }}'
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver

- name: postgresql SSL - reload PostgreSQL to enable ssl on
- name: reload postgresql to turn SSL on
become_user: '{{ pg_user }}'
become: true
service:
name: '{{ postgresql_service }}'
state: reloaded
postgresql_query:
autocommit: yes
db: postgres
login_user: '{{ pg_user }}'
port: '54{{ pg_ver }}'
query: 'SELECT pg_reload_conf()'
with_sequence: start=10 count=5
loop_control:
loop_var: pg_ver
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ postgresql_packages:
- "postgresql-common"
- "python-psycopg2"

pg_hba_location: "/etc/postgresql/9.4/main/pg_hba.conf"
pg_dir: "/var/lib/postgresql/9.4/main"
pg_hba_location: "/etc/postgresql/{{ pg_ver }}/main/pg_hba.conf"
pg_dir: "/var/lib/postgresql/{{ pg_ver }}/main"
pg_ver: 9.4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
postgresql_packages:
- "postgresql-server"
- "postgresql{{ pg_ver }}-server"
- "python3-psycopg2"
- "bzip2"
- "xz"

pg_hba_location: "/var/lib/pgsql/data/pg_hba.conf"
pg_dir: "/var/lib/pgsql/data"
pg_hba_location: "{{pg_dir}}/pg_hba.conf"
pg_dir: "/var/lib/pgsql/{{ pg_ver }}/data"
Loading