From 12b319171aeab3b419712c6b6d1cd66b7d58ba7e Mon Sep 17 00:00:00 2001 From: Attilio Greco Date: Tue, 24 May 2022 18:51:03 +0200 Subject: [PATCH] add timescale installation --- defaults/main.yml | 10 +++-- molecule/default/prepare.yml | 11 ++++++ tasks/extension/postgis.yaml | 16 ++++++++ tasks/extension/timescale.yaml | 13 +++++++ tasks/install.yml | 47 +++++++++++++++--------- templates/installation/timescale.repo.j2 | 10 +++++ templates/postgresql.conf.j2 | 5 ++- 7 files changed, 91 insertions(+), 21 deletions(-) create mode 100644 tasks/extension/postgis.yaml create mode 100644 tasks/extension/timescale.yaml create mode 100644 templates/installation/timescale.repo.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 5860352..bd31e15 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,17 +4,19 @@ postgres_repo: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_ postgres_version: 13 postgis_install: true postgis_version: 31 +postgis_version_pakage_name: postgis{{postgis_version}}_{{postgres_version}} pg_config_listen_addresses: localhost pg_config_port: 5432 pg_config_max_connections: 1024 -pg_config_shared_buffers: 2GB +pg_config_shared_buffers: 128MB pg_config_temp_buffers: 8MB pg_config_work_mem: 4MB pg_config_max_wal_size: 1GB -pg_config_min_wal_size: 4G +pg_config_min_wal_size: 256MB pg_config_log_filename: postgresql-%Y-%m-%d_%H%M%S.log pg_config_timezone: "Europe/Rome" pg_config_row: "" +pg_config_shared_preload_libraries: [] # pg_config_row: | # max_connections = 200 # effective_cache_size = 6GB @@ -31,7 +33,9 @@ pg_config_row: "" # max_parallel_workers_per_gather = 1 # max_parallel_workers = 2 # max_parallel_maintenance_workers = 1 - +additional_extension: + # - postgis + - timescale pg_hba_user_options: - contype: host users: all diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 1754d9d..976b3a9 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,7 +1,18 @@ +- name: Connection Wait + hosts: all + become: true + gather_facts: no + tasks: + - name: Wait 60 seconds, but only start checking after 15 seconds + wait_for_connection: + delay: 15 + timeout: 60 + - name: prepare hosts: all become: true tasks: + - name: prepare | install python3-pip dnf: name: diff --git a/tasks/extension/postgis.yaml b/tasks/extension/postgis.yaml new file mode 100644 index 0000000..bd5f53a --- /dev/null +++ b/tasks/extension/postgis.yaml @@ -0,0 +1,16 @@ +- name: postgres | install | extension | postgis | add powertools repository + yum_repository: + name: powertools + description: Rocky Linux $releasever - PowerTools + file: external_repos + mirrorlist: https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=PowerTools-$releasever + gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial + enabled: yes + +- name: postgres | install | extension | postgis | enable powertools and install "{{postgis_version_pakage_name}}" + dnf: + enablerepo: powertools + name: + - "{{postgis_version_pakage_name}}" + state: present + when: postgis_install \ No newline at end of file diff --git a/tasks/extension/timescale.yaml b/tasks/extension/timescale.yaml new file mode 100644 index 0000000..5e9854f --- /dev/null +++ b/tasks/extension/timescale.yaml @@ -0,0 +1,13 @@ + +- name: postgres | install | extension | timescale | add timescale repo + ansible.builtin.template: + src: installation/timescale.repo.j2 + dest: /etc/yum.repos.d/timescale_timescaledb.repo + +- name: postgres | install | install postgresql + dnf: + name: + - timescaledb-2-postgresql-{{postgres_version}} + state: present + notify: + - restart postgreql \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml index 5b5e6ed..2ef241e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,7 +1,32 @@ --- +- name: Distribution + debug: + msg: "{{ ansible_distribution }}" + +- name: Distribution version + debug: + msg: "{{ ansible_distribution_version}}" + +- name: Distribution major version + debug: + msg: "{{ ansible_distribution_major_version }}" + +- name: postgres | install | postgres pre-install show shared_preload_libraries list + debug: + msg: "{{ pg_config_shared_preload_libraries + ['timescaledb'] }}" + +- name: postgres | install | timescale pre-install + set_fact: + pg_config_shared_preload_libraries: "{{ pg_config_shared_preload_libraries + ['timescaledb'] }}" + when: '"timescale" in additional_extension' + +- name: postgres | install | postgres pre-install show shared_preload_libraries list + debug: + msg: "{{ pg_config_shared_preload_libraries }}" + - name: postgres | install | install postgres repo dnf: - name: 'https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm' + name: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ ansible_distribution_major_version }}-x86_64/pgdg-redhat-repo-latest.noarch.rpm" state: present disable_gpg_check: yes @@ -23,19 +48,7 @@ name: epel-release state: present -- name: postgres | install | enabled repo powertools - yum_repository: - name: powertools - description: Rocky Linux $releasever - PowerTools - file: external_repos - mirrorlist: https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=PowerTools-$releasever - gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial - enabled: yes - -- name: postgres | install | install postgis - dnf: - enablerepo: powertools - name: - - postgis31_13 - state: present - when: postgis_install \ No newline at end of file +- name: postgres | install | install custom extension + include_tasks: "tasks/extension/{{ item }}.yaml" + with_items: "{{ additional_extension }}" + # when: additional_extension \ No newline at end of file diff --git a/templates/installation/timescale.repo.j2 b/templates/installation/timescale.repo.j2 new file mode 100644 index 0000000..3e2a820 --- /dev/null +++ b/templates/installation/timescale.repo.j2 @@ -0,0 +1,10 @@ +[timescale_timescaledb] +name=timescale_timescaledb +baseurl=https://packagecloud.io/timescale/timescaledb/el/{{ ansible_distribution_major_version }}/$basearch +repo_gpgcheck=1 +gpgcheck=0 +enabled=1 +gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey +sslverify=1 +sslcacert=/etc/pki/tls/certs/ca-bundle.crt +metadata_expire=300 \ No newline at end of file diff --git a/templates/postgresql.conf.j2 b/templates/postgresql.conf.j2 index 4b6033a..baba026 100644 --- a/templates/postgresql.conf.j2 +++ b/templates/postgresql.conf.j2 @@ -710,8 +710,11 @@ lc_time = 'en_US.UTF-8' # locale for time formatting default_text_search_config = 'pg_catalog.english' # - Shared Library Preloading - - +{% if pg_config_shared_preload_libraries %} +shared_preload_libraries = '{{ pg_config_shared_preload_libraries | join(',') }}' +{% else %} #shared_preload_libraries = '' # (change requires restart) +{% endif %} #local_preload_libraries = '' #session_preload_libraries = '' #jit_provider = 'llvmjit' # JIT library to use