diff --git a/tests/integration/targets/setup_postgresql_db/tasks/main.yml b/tests/integration/targets/setup_postgresql_db/tasks/main.yml index 717f5c00c2..24a121930e 100644 --- a/tests/integration/targets/setup_postgresql_db/tasks/main.yml +++ b/tests/integration/targets/setup_postgresql_db/tasks/main.yml @@ -2,10 +2,12 @@ set_fact: python_suffix: '' when: ansible_python_version is version('3', '<') + - name: python 3 set_fact: python_suffix: -py3 when: ansible_python_version is version('3', '>=') + - name: Include distribution and Python version specific variables include_vars: '{{ lookup(''first_found'', params) }}' vars: @@ -17,26 +19,31 @@ - default{{ python_suffix }}.yml paths: - '{{ role_path }}/vars' + - 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: stop postgresql service service: name={{ postgresql_service }} state=stopped ignore_errors: true + - name: remove old db (RedHat or Suse) file: path: '{{ pg_dir }}' state: absent ignore_errors: true when: ansible_os_family == "RedHat" or ansible_os_family == "Suse" + - name: remove old db (FreeBSD) file: path: '{{ pg_dir }}' state: absent ignore_errors: true when: ansible_os_family == "FreeBSD" + - name: remove old db config and files (debian) file: path: '{{ loop_item }}' @@ -48,6 +55,7 @@ - /var/lib/postgresql loop_control: loop_var: loop_item + - name: install dependencies for postgresql test package: name: '{{ postgresql_package_item }}' @@ -55,23 +63,29 @@ with_items: '{{ postgresql_packages }}' loop_control: loop_var: postgresql_package_item + - name: initialize postgres (FreeBSD) command: /usr/local/etc/rc.d/postgresql oneinitdb when: ansible_os_family == "FreeBSD" + - 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" + - name: Initialize postgres (Debian) shell: . /usr/share/postgresql-common/maintscripts-functions && set_system_locale && /usr/bin/pg_createcluster -u postgres {{ pg_verĀ }} main args: creates: /etc/postgresql/{{ pg_ver }}/ when: ansible_os_family == 'Debian' + - name: Initialize postgres (Suse) service: name=postgresql state=restarted when: ansible_os_family == 'Suse' + - name: Copy pg_hba into place template: src: files/pg_hba.conf @@ -79,6 +93,7 @@ owner: '{{ pg_user }}' group: '{{ pg_group }}' mode: '0644' + - name: Generate locales (Debian) locale_gen: name: '{{ item }}' @@ -87,6 +102,7 @@ - pt_BR - es_ES when: ansible_os_family == 'Debian' + - block: - name: Install langpacks (RHEL8) yum: @@ -96,6 +112,7 @@ - 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 @@ -105,16 +122,19 @@ - pt_BR loop_control: loop_var: locale + - name: Reinstall internationalization files shell: yum -y reinstall glibc-common || yum -y install glibc-common args: warn: false when: locale_present is failed + - name: Generate locale (RedHat) command: localedef -f ISO-8859-1 -i {{ item.locale }} {{ item.locale }} when: item is failed with_items: '{{ locale_present.results }}' when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora' + - name: Install glibc langpacks (Fedora >= 24) package: name: '{{ item }}' @@ -123,21 +143,26 @@ - glibc-langpack-es - glibc-langpack-pt when: ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('24', '>=') + - name: enable postgresql service (FreeBSD) lineinfile: path: /etc/rc.conf line: postgresql_enable="YES" when: ansible_os_family == "FreeBSD" + - name: start postgresql service service: name={{ postgresql_service }} state=started + - name: restart postgresql service service: name={{ postgresql_service }} state=restarted + - 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 }}' @@ -148,6 +173,7 @@ - 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 }} @@ -157,14 +183,17 @@ - dummy--1.0--2.0.sql - dummy--2.0--3.0.sql when: ansible_os_family == 'Debian' + - name: Get PostgreSQL version become_user: '{{ pg_user }}' become: true shell: echo 'SHOW SERVER_VERSION' | psql --tuples-only --no-align --dbname postgres register: postgres_version_resp + - name: Print PostgreSQL server version debug: msg: '{{ postgres_version_resp.stdout }}' + - import_tasks: ssl.yml when: - ansible_os_family == 'Debian' diff --git a/tests/integration/targets/setup_postgresql_db/tasks/ssl.yml b/tests/integration/targets/setup_postgresql_db/tasks/ssl.yml index 5e44b7c2fe..1bc4411d00 100644 --- a/tests/integration/targets/setup_postgresql_db/tasks/ssl.yml +++ b/tests/integration/targets/setup_postgresql_db/tasks/ssl.yml @@ -3,6 +3,7 @@ become: true postgresql_db: name: '{{ ssl_db }}' + - name: postgresql SSL - create role become_user: '{{ pg_user }}' become: true @@ -10,25 +11,31 @@ name: '{{ ssl_user }}' role_attr_flags: SUPERUSER password: '{{ ssl_pass }}' + - name: postgresql SSL - install openssl become: true package: name=openssl state=present + - name: postgresql SSL - create certs 1 become_user: root become: true shell: openssl req -new -nodes -text -out ~{{ pg_user }}/root.csr \ -keyout ~{{ pg_user }}/root.key -subj "/CN=localhost.local" + - name: postgresql SSL - create certs 2 become_user: root become: true shell: openssl x509 -req -in ~{{ pg_user }}/root.csr -text -days 3650 \ -extensions v3_ca -signkey ~{{ pg_user }}/root.key -out ~{{ pg_user }}/root.crt + - name: postgresql SSL - create certs 3 become_user: root become: true shell: openssl req -new -nodes -text -out ~{{ pg_user }}/server.csr \ -keyout ~{{ pg_user }}/server.key -subj "/CN=localhost.local" + - name: postgresql SSL - create certs 4 become_user: root become: true shell: openssl x509 -req -in ~{{ pg_user }}/server.csr -text -days 365 \ -CA ~{{ pg_user }}/root.crt -CAkey ~{{ pg_user }}/root.key -CAcreateserial -out server.crt + - name: postgresql SSL - set right permissions to files become_user: root become: true @@ -42,6 +49,7 @@ - ~{{ pg_user }}/server.key - ~{{ pg_user }}/root.crt - ~{{ pg_user }}/server.csr + - name: postgresql SSL - enable SSL become_user: '{{ pg_user }}' become: true @@ -50,6 +58,7 @@ db: postgres name: ssl value: true + - name: postgresql SSL - reload PostgreSQL to enable ssl on become: true service: