2017-01-05 01:41:18 +01:00
|
|
|
|
- name: python 2
|
|
|
|
|
set_fact:
|
|
|
|
|
python_suffix: ""
|
2017-11-27 23:58:08 +01:00
|
|
|
|
when: ansible_python_version is version('3', '<')
|
2017-01-05 01:41:18 +01:00
|
|
|
|
|
|
|
|
|
- name: python 3
|
|
|
|
|
set_fact:
|
|
|
|
|
python_suffix: "-py3"
|
2017-11-27 23:58:08 +01:00
|
|
|
|
when: ansible_python_version is version('3', '>=')
|
2017-01-05 01:41:18 +01:00
|
|
|
|
|
2014-12-02 03:57:40 +01:00
|
|
|
|
- include_vars: '{{ item }}'
|
|
|
|
|
with_first_found:
|
|
|
|
|
- files:
|
2017-01-05 01:41:18 +01:00
|
|
|
|
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
|
|
|
|
|
- '{{ ansible_distribution }}-{{ ansible_distribution_version }}{{ python_suffix }}.yml'
|
|
|
|
|
- '{{ ansible_os_family }}{{ python_suffix }}.yml'
|
|
|
|
|
- 'default{{ python_suffix }}.yml'
|
2014-12-02 03:57:40 +01:00
|
|
|
|
paths: '../vars'
|
|
|
|
|
|
2019-04-06 01:44:09 +02:00
|
|
|
|
- name: make sure the dbus service is started under systemd
|
|
|
|
|
systemd:
|
|
|
|
|
name: dbus
|
|
|
|
|
state: started
|
|
|
|
|
when: ansible_service_mgr == 'systemd' and ansible_distribution == 'Fedora'
|
|
|
|
|
|
2014-12-02 03:57:40 +01:00
|
|
|
|
# Make sure we start fresh
|
2017-01-26 03:45:28 +01:00
|
|
|
|
- name: stop postgresql service
|
|
|
|
|
service: name={{ postgresql_service }} state=stopped
|
|
|
|
|
ignore_errors: True
|
|
|
|
|
|
2016-05-31 23:47:36 +02:00
|
|
|
|
- name: remove old db (RedHat or Suse)
|
2019-07-17 17:00:40 +02:00
|
|
|
|
file:
|
|
|
|
|
path: "{{ pg_dir }}"
|
|
|
|
|
state: absent
|
2014-12-02 03:57:40 +01:00
|
|
|
|
ignore_errors: True
|
2016-05-31 23:47:36 +02:00
|
|
|
|
when: ansible_os_family == "RedHat" or ansible_os_family == "Suse"
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2017-01-26 03:45:28 +01:00
|
|
|
|
- name: remove old db (FreeBSD)
|
|
|
|
|
file:
|
|
|
|
|
path: "{{ pg_dir }}"
|
|
|
|
|
state: absent
|
2014-12-02 03:57:40 +01:00
|
|
|
|
ignore_errors: True
|
2019-07-17 17:00:40 +02:00
|
|
|
|
when: ansible_os_family == "FreeBSD"
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2019-07-17 17:00:40 +02:00
|
|
|
|
# Theoretically, pg_dropcluster should work but it doesn't so remove files
|
|
|
|
|
- name: remove old db config and files (debian)
|
|
|
|
|
file:
|
|
|
|
|
path: '{{ loop_item }}'
|
|
|
|
|
state: absent
|
2014-12-02 03:57:40 +01:00
|
|
|
|
ignore_errors: True
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2019-07-17 17:00:40 +02:00
|
|
|
|
loop:
|
|
|
|
|
- /etc/postgresql
|
|
|
|
|
- /var/lib/postgresql
|
|
|
|
|
loop_control:
|
|
|
|
|
loop_var: loop_item
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2017-04-28 03:09:40 +02:00
|
|
|
|
- name: install dependencies for postgresql test
|
|
|
|
|
package: name={{ postgresql_package_item }} state=present
|
|
|
|
|
with_items: "{{ postgresql_packages }}"
|
2015-10-23 09:27:09 +02:00
|
|
|
|
loop_control:
|
|
|
|
|
loop_var: postgresql_package_item
|
2017-01-26 03:45:28 +01:00
|
|
|
|
|
|
|
|
|
- name: initialize postgres (FreeBSD)
|
|
|
|
|
command: /usr/local/etc/rc.d/postgresql oneinitdb
|
|
|
|
|
when: ansible_os_family == "FreeBSD"
|
|
|
|
|
|
2016-04-23 22:43:11 +02:00
|
|
|
|
- name: Initialize postgres (RedHat systemd)
|
2014-12-02 03:57:40 +01:00
|
|
|
|
command: postgresql-setup initdb
|
2017-04-28 03:09:40 +02:00
|
|
|
|
when: ansible_os_family == "RedHat" and ansible_service_mgr == "systemd"
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2016-04-23 22:43:11 +02:00
|
|
|
|
- name: Initialize postgres (RedHat sysv)
|
2014-12-02 03:57:40 +01:00
|
|
|
|
command: /sbin/service postgresql initdb
|
2017-04-28 03:09:40 +02:00
|
|
|
|
when: ansible_os_family == "RedHat" and ansible_service_mgr != "systemd"
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2017-04-28 03:09:40 +02:00
|
|
|
|
- name: Initialize postgres (Debian)
|
2017-05-07 16:22:43 +02:00
|
|
|
|
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 }}/"
|
2014-12-03 16:37:51 +01:00
|
|
|
|
when: ansible_os_family == 'Debian'
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2016-05-31 23:47:36 +02:00
|
|
|
|
- name: Initialize postgres (Suse)
|
|
|
|
|
service: name=postgresql state=restarted
|
|
|
|
|
when: ansible_os_family == 'Suse'
|
|
|
|
|
|
2014-12-02 03:57:40 +01:00
|
|
|
|
- name: Copy pg_hba into place
|
2017-01-26 03:45:28 +01:00
|
|
|
|
template:
|
|
|
|
|
src: files/pg_hba.conf
|
|
|
|
|
dest: "{{ pg_hba_location }}"
|
|
|
|
|
owner: "{{ pg_user }}"
|
|
|
|
|
group: "{{ pg_group }}"
|
|
|
|
|
mode: "0644"
|
2014-12-02 03:57:40 +01:00
|
|
|
|
|
2017-04-14 16:07:34 +02:00
|
|
|
|
- name: Generate locales (Debian)
|
|
|
|
|
locale_gen:
|
|
|
|
|
name: '{{ item }}'
|
|
|
|
|
state: present
|
|
|
|
|
with_items:
|
|
|
|
|
- pt_BR
|
|
|
|
|
- es_ES
|
2014-12-02 03:57:40 +01:00
|
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
|
|
2017-04-28 03:09:40 +02:00
|
|
|
|
# Suse: locales are installed by default (glibc-locale package).
|
|
|
|
|
# Fedora 23: locales are installed by default (glibc-common package)
|
|
|
|
|
# CentOS: all locales are installed by default (glibc-common package) but some
|
|
|
|
|
# RPM macros could prevent their installation (for example when using anaconda
|
|
|
|
|
# instLangs parameter).
|
|
|
|
|
|
|
|
|
|
- block:
|
2019-11-15 23:00:27 +01:00
|
|
|
|
- name: Install langpacks (RHEL8)
|
2018-11-20 18:49:21 +01:00
|
|
|
|
yum:
|
2019-11-15 23:00:27 +01:00
|
|
|
|
name:
|
|
|
|
|
- glibc-langpack-es
|
|
|
|
|
- glibc-langpack-pt
|
|
|
|
|
- glibc-all-langpacks
|
2018-11-20 18:49:21 +01:00
|
|
|
|
state: present
|
2019-11-15 23:00:27 +01:00
|
|
|
|
when: ansible_distribution_major_version is version('8', '>=')
|
2018-11-20 18:49:21 +01:00
|
|
|
|
|
2017-04-28 03:09:40 +02:00
|
|
|
|
- name: Check if locales need to be generated (RedHat)
|
|
|
|
|
shell: "localedef --list-archive | grep -a -q '^{{ locale }}$'"
|
|
|
|
|
register: locale_present
|
|
|
|
|
ignore_errors: True
|
|
|
|
|
with_items:
|
|
|
|
|
- es_ES
|
|
|
|
|
- pt_BR
|
|
|
|
|
loop_control:
|
|
|
|
|
loop_var: locale
|
|
|
|
|
|
|
|
|
|
- name: Generate locale (RedHat)
|
|
|
|
|
command: 'localedef -f ISO-8859-1 -i {{ item.locale }} {{ item.locale }}'
|
2017-11-27 23:58:08 +01:00
|
|
|
|
when: item is failed
|
2017-04-28 03:09:40 +02:00
|
|
|
|
with_items: '{{ locale_present.results }}'
|
|
|
|
|
when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
|
|
|
|
|
|
|
|
|
|
- name: Install glibc langpacks (Fedora >= 24)
|
|
|
|
|
package:
|
|
|
|
|
name: '{{ item }}'
|
|
|
|
|
state: 'latest'
|
|
|
|
|
with_items:
|
|
|
|
|
- glibc-langpack-es
|
|
|
|
|
- glibc-langpack-pt
|
2019-11-15 23:00:27 +01:00
|
|
|
|
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('24', '>=')
|
2014-12-10 23:25:40 +01:00
|
|
|
|
|
2017-01-26 03:45:28 +01:00
|
|
|
|
- name: enable postgresql service (FreeBSD)
|
|
|
|
|
lineinfile:
|
|
|
|
|
path: /etc/rc.conf
|
|
|
|
|
line: 'postgresql_enable="YES"'
|
|
|
|
|
when: ansible_os_family == "FreeBSD"
|
|
|
|
|
|
|
|
|
|
- name: start postgresql service
|
|
|
|
|
# work-around for issue on FreeBSD where service won't restart if currently stopped
|
|
|
|
|
service: name={{ postgresql_service }} state=started
|
|
|
|
|
|
2014-12-02 03:57:40 +01:00
|
|
|
|
- name: restart postgresql service
|
|
|
|
|
service: name={{ postgresql_service }} state=restarted
|
2019-07-02 15:24:46 +02:00
|
|
|
|
|
|
|
|
|
########################
|
|
|
|
|
# Setup dummy extension:
|
|
|
|
|
- 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--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--1.0--2.0.sql
|
|
|
|
|
- dummy--2.0--3.0.sql
|
|
|
|
|
when: ansible_os_family == 'Debian'
|
2019-07-17 17:00:40 +02:00
|
|
|
|
|
|
|
|
|
- name: Get PostgreSQL version
|
|
|
|
|
become_user: "{{ pg_user }}"
|
|
|
|
|
become: yes
|
|
|
|
|
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 }}"
|
2019-09-25 15:03:48 +02:00
|
|
|
|
|
|
|
|
|
# SSL configuration.
|
|
|
|
|
# Restricted using Debian family because of there are errors on other distributions
|
|
|
|
|
# that not related with PostgreSQL or psycopg2 SSL support.
|
|
|
|
|
# The tests key point is to be sure that ssl options work in general
|
|
|
|
|
- import_tasks: ssl.yml
|
|
|
|
|
when:
|
|
|
|
|
- ansible_os_family == 'Debian'
|
|
|
|
|
- postgres_version_resp.stdout is version('9.4', '>=')
|