Skip to content

Commit

Permalink
Merge pull request #5 from idealista/develop
Browse files Browse the repository at this point in the history
Develop to Master for release 1.0.1
  • Loading branch information
ommarmol authored Jun 25, 2024
2 parents 40692df + d7b11fe commit 1a32b0a
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch
### Removed
### Fixed

## [1.0.1](https://github.com/idealista/patroni_role/tree/1.0.1) (2024-06-20)
### [Full Changelog](https://github.com/idealista/patroni_role/compare/1.0.0...1.0.1)
### Changed
- *[#2](https://github.com/idealista/consul_role/issues/2) task find oracle instantclient* @ledepedro
- *DNS to IP in listen_addresses and connect_addres in patroni.yml* @ledepedro
- *add path_role in incluede extensions* @ledepedro
### Added
- *[#2](https://github.com/idealista/consul_role/issues/2) Add newer extensions postgresql pgvector, pgvectorscale* @ledepedro

## [1.0.0](https://github.com/idealista/patroni_role/tree/1.0.0)
### Added
- *Initial release* @ledepedro
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ postgresql:
# data_checksums: true
# password_encryption_algorithm: 'scram-sha-256'
# postgresql.extensions: []
# postgresql.extensions_install: [] # 'h3-pg', 'mysql_fdw', 'oracle_fdw', 'pgrouting', 'pgsql_postal', 'postgis', 'rum'
# postgresql.extensions_install: [] # 'h3-pg', 'mysql_fdw', 'oracle_fdw', 'pgrouting', 'pgsql_postal', 'pgvector', 'pgvectorscale', 'postgis', 'rum'
# h3_install_version: 'latest'
# max_connections: '500'
# superuser_reserved_connections: '5'
Expand Down
2 changes: 2 additions & 0 deletions molecule/default/group_vars/all/main
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ postgresql:
# - 'mysql_fdw'
# - 'oracle_fdw'
# - 'pgrouting'
# - 'pgvector'
# - 'pgvectorscale'
# - 'pgsql_postal'
# - 'postgis'
# - 'rum'
Expand Down
2 changes: 1 addition & 1 deletion tasks/postgresql/extensions-install/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Include extension to install
include_tasks: "{{ extension_item | lower }}.yml"
include_tasks: "{{ role_path }}/tasks/postgresql/extensions-install/{{ extension_item | lower }}.yml"
loop: "{{ postgresql_extensions_install | flatten(1) }}"
loop_control:
loop_var: extension_item
Expand Down
30 changes: 23 additions & 7 deletions tasks/postgresql/extensions-install/oracle_fdw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,35 @@
- name: oracle_fdw - Instalar extensión oracle_fdw si no está instalada
block:
- name: oracle_fdw - Verificar si oracle instantclient sdk está instalada
shell: "find / -name oci.h"
find:
paths: /
patterns: oci.h
recurse: true
file_type: file
register: find_oci_h

- name: oracle_fdw - Verificar si oracle instantclient sqlplus está instalada
shell: "find / -name libsqlplus.so"
find:
paths: /
patterns: libsqlplus.so
recurse: true
file_type: file
register: find_sqlplus

- name: oracle_fdw - Oracle instantclient presente
debug:
msg: "oracle_fdw - oracle instantclient esta instalado"
when: (find_oci_h.stdout_lines | length | bool) and
(find_sqlplus.stdout_lines | length | bool)
when: find_oci_h.matched > 0 and
find_sqlplus.matched > 0

- name: oracle_fdw - Instalar oracle instantclient
block:
- name: Create /data/oracle dir
- name: Instalar unzip si no está presente
become: true
package:
name: unzip
state: present
- name: Crear /data/oracle dir
file:
path: "/data/oracle"
state: directory
Expand Down Expand Up @@ -93,8 +109,8 @@
shell: source /etc/profile.d/oracle-instantclient.sh
args:
executable: /bin/bash
when: (find_oci_h.stdout_lines | length | bool) == false or
(find_sqlplus.stdout_lines | length | bool) == false
when: find_oci_h.matched == 0 or
find_sqlplus.matched == 0

- name: oracle_fdw - Instalar dependencias
apt:
Expand Down
62 changes: 62 additions & 0 deletions tasks/postgresql/extensions-install/pgvector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---

- block:

- name: pgvector - get pkglibdir
shell: |
pg_config --pkglibdir
register: pkglibdir_result
changed_when: false

- name: pgvector - Verificar la presencia de la extensión vector
stat:
path: "{{ pkglibdir_result.stdout_lines[0] }}/vector.so"
register: extension_check

- name: pgvector - vector está presente
debug:
msg: "vector esta instalado"
when: extension_check.stat.exists

- name: pgvector - Instalar extensión vector si no está instalada
block:

- name: Actualizar el caché de apt
apt:
update_cache: true

- name: Instalar dependencias necesarias
apt:
name:
- postgresql-server-dev-{{ postgresql_version }}
- git
- make
state: present

- name: Clonar el repositorio pgvector
git:
repo: "https://github.com/pgvector/pgvector.git"
dest: /tmp/pgvector
version: master

- name: Compilar e instalar pgvector
make:
chdir: /tmp/pgvector
target: install

- name: Limpiar archivos temporales
file:
path: /tmp/pgvector
state: absent
force: true

when: extension_check.stat.exists == false

when: postgresql_version | int >= 12
tags: postgresql_extensions_install, pgvector

- name: pgvector - vector postgres no permitida
debug:
msg: "pgversion extension has not been installed, requires postgresql 12 or higher"
when: postgresql_version | int < 12
tags: postgresql_extensions_install, pgvector
103 changes: 103 additions & 0 deletions tasks/postgresql/extensions-install/pgvectorscale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---

- block:

- name: pgvectorscale - get pkglibdir
shell: |
pg_config --pkglibdir
register: pkglibdir_result
changed_when: false

- name: pgvectorscale - Verificar la presencia de la extensión vector
stat:
path: "{{ pkglibdir_result.stdout_lines[0] }}/vector.so"
register: extension_check

- name: pgvectorscale - vector está presente
debug:
msg: "vector esta instalado"
when: extension_check.stat.exists

- name: pgvectorscale - Instalar extensión vector si no está instalada
block:

- name: Include vector extension to install
include_tasks: "{{ role_path }}/tasks/postgresql/extensions-install/pgvector.yml"

when: extension_check.stat.exists == false

- name: pgvectorscale - Verificar la presencia de la extensión vectorscale
find:
paths: "{{ pkglibdir_result.stdout_lines[0] }}"
patterns: "vectorscale*.so"
register: extension_check

- name: pgvectorscale - vectorscale está presente
debug:
msg: "vector esta instalado"
when: extension_check.matched > 0

- name: pgvectorscale - Instalar extensión vectorscale si no está instalada
block:

- name: pgvectorscale - Actualizar el caché de apt
apt:
update_cache: true

- name: pgvectorscale - Instalar dependencias necesarias
apt:
name:
- postgresql-server-dev-{{ postgresql_version }}
- git
- make
- gcc
- pkg-config
- clang
- libssl-dev
- libopenblas-dev
- curl
state: present

- name: pgvectorscale - Install Rustup
shell: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
args:
creates: /root/.cargo/bin/rustc # Esto previene que se ejecute si Rust ya está instalado
environment:
- CARGO_HOME: /root/.cargo
- RUSTUP_HOME: /root/.rustup

- name: pgvectorscale - Install cargo-pgrx
shell: /root/.cargo/bin/cargo install --locked cargo-pgrx

- name: pgvectorscale - pgrx development environment
shell: /root/.cargo/bin/cargo pgrx init --pg16 pg_config

- name: pgvectorscale - Clonar el repositorio pgvectorscale
git:
repo: "https://github.com/timescale/pgvectorscale.git"
dest: /tmp/pgvectorscale
version: main

- name: pgvectorscale - Configurar RUSTFLAGS y compilar e instalar pgvectorscale
shell: |
export RUSTFLAGS="-C target-feature=+avx2,+fma"
/root/.cargo/bin/cargo pgrx install --release
args:
chdir: /tmp/pgvectorscale/pgvectorscale

- name: pgvectorscale - Limpiar archivos temporales
file:
path: /tmp/pgvectorscale
state: absent
force: true

when: extension_check.matched == 0

when: postgresql_version | int >= 16
tags: postgresql_extensions_install, pgvectorscale

- name: pgvectorscale - versión de postgres no permitida
debug:
msg: "pgvectorscale extension has not been installed, requires postgresql 16 or higher"
when: postgresql_version | int < 16
tags: postgresql_extensions_install, pgvectorscale
4 changes: 4 additions & 0 deletions tasks/pre-checks/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
ansible.builtin.stat:
path: "{{ postgresql_conf_dir }}/postgresql.conf"
register: postgresql_conf_file
tags: always
- name: Check Postgres installed
set_fact:
postgres_installed: "{{ postgresql_conf_file.stat.exists }}"
tags: always

- name: Prepare PostgreSQL | make sure the PgBouncer config files exists
ansible.builtin.stat:
path: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
register: pgbouncer_conf_file
tags: always
- name: Check PgBouncer installed
set_fact:
pgbouncer_installed: "{{ pgbouncer_conf_file.stat.exists }}"
tags: always
6 changes: 3 additions & 3 deletions templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ bootstrap:

postgresql:
{% if not with_haproxy_load_balancing|bool and not pgbouncer_install|bool and (cluster_vip is defined and cluster_vip | length > 0) %}
listen: {{ ansible_host }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}
listen: {{ hostvars[inventory_hostname].host_ip | default (hostvars[inventory_hostname]['ansible_default_ipv4']['address']) }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}
{% else %}
listen: {{ ansible_host }},127.0.0.1:{{ postgresql_port }}
listen: {{ hostvars[inventory_hostname].host_ip | default (hostvars[inventory_hostname]['ansible_default_ipv4']['address']) }},127.0.0.1:{{ postgresql_port }}
{% endif %}
connect_address: {{ ansible_host }}:{{ postgresql_port }}
connect_address: {{ hostvars[inventory_hostname].host_ip | default (hostvars[inventory_hostname]['ansible_default_ipv4']['address']) }}:{{ postgresql_port }}
{% if patroni_superuser_username == 'postgres' %}
use_unix_socket: true
{% endif %}
Expand Down

0 comments on commit 1a32b0a

Please sign in to comment.