add timescale and postgrest

This commit is contained in:
Attilio Greco 2022-05-26 14:08:42 +02:00
parent 12b319171a
commit e8e640fa28
10 changed files with 214 additions and 10 deletions

View File

@ -1,10 +1,7 @@
--- ---
# defaults file for postgres # defaults file for postgres
postgres_repo: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm" postgres_repo: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
postgres_version: 13 postgres_version: 14
postgis_install: true
postgis_version: 31
postgis_version_pakage_name: postgis{{postgis_version}}_{{postgres_version}}
pg_config_listen_addresses: localhost pg_config_listen_addresses: localhost
pg_config_port: 5432 pg_config_port: 5432
pg_config_max_connections: 1024 pg_config_max_connections: 1024
@ -36,6 +33,7 @@ pg_config_shared_preload_libraries: []
additional_extension: additional_extension:
# - postgis # - postgis
- timescale - timescale
- PostgREST
pg_hba_user_options: pg_hba_user_options:
- contype: host - contype: host
users: all users: all
@ -57,3 +55,15 @@ pg_hba_user_options:
source: 192.169.100.1/24 source: 192.169.100.1/24
databases: all databases: all
method: md5 method: md5
# keepd as described in ufficial doc example:
# https://postgrest.org/en/stable/tutorials/tut0.html
postgrest_version: latest
postgrest_db_uri: "postgres://authenticator:mysecretpassword@localhost:5432/postgres"
postgrest_db_schemas: "api"
postgrest_db_anon_role: "web_anon"
# postgis
postgis_version_pakage_name: postgis{{postgis_version}}_{{postgres_version}}
postgis_install: true
postgis_version: 31
# Postgres configuration

View File

@ -15,3 +15,18 @@
ansible.builtin.systemd: ansible.builtin.systemd:
state: reloaded state: reloaded
name: "postgresql-{{postgres_version}}" name: "postgresql-{{postgres_version}}"
- name: reloaded postgrest
ansible.builtin.systemd:
state: reloaded
name: "postgrest"
- name: started postgrest
ansible.builtin.systemd:
state: started
name: "postgrest"
- name: restarted postgrest
ansible.builtin.systemd:
state: restarted
name: "postgrest"

View File

@ -4,9 +4,11 @@ driver:
name: libvirt name: libvirt
platforms: platforms:
- name: instance-1 - name: instance-1
image_url: "http://remoteshare.4sigma.top/Rocky8.4-try-srinked.qcow2" # image_url: "http://127.0.0.1:8000/Rocky-8-GenericCloud-8.6-20220515.x86_64.qcow2"
disk_size: "10G" image_url: "http://127.0.0.1:8000/Rocky-8-GenericCloud-8.5-20211114.2.x86_64.qcow2"
memory_size: "1" # in GB disk_size: "15G"
default_vcpu: 2
memory_size: "1"
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:

View File

@ -8,6 +8,10 @@
delay: 15 delay: 15
timeout: 60 timeout: 60
- name: set timezone to Europe/Rome
timezone:
name: Europe/Rome
- name: prepare - name: prepare
hosts: all hosts: all
become: true become: true
@ -19,6 +23,10 @@
- python3-pip - python3-pip
- python3-devel - python3-devel
- gcc - gcc
- net-tools
- vim
- iotop
- bash-completion
- name: prepare | create ansible requirements - name: prepare | create ansible requirements
ansible.builtin.file: ansible.builtin.file:

View File

@ -8,7 +8,7 @@
tasks: tasks:
- name: Verify | check postgres is running - name: Verify | check postgres is running
ansible.builtin.systemd: ansible.builtin.systemd:
name: postgresql-13.service name: postgresql-{{ }}.service
state: started state: started
- name: create sql testing file - name: create sql testing file

View File

@ -0,0 +1,103 @@
- name: postgres | tasks | extension | PostgREST | create userand group | create group for postgrest
ansible.builtin.group:
name: postgrest
state: present
system: yes
- name: postgres | tasks | extension | PostgREST | create userand group | create user for postgrest
ansible.builtin.user:
name: postgrest
group: postgrest
createhome: no
system: yes
state: present
- name: postgres | tasks | extension | PostgREST | get tags | show version selected
debug:
var: postgrest_version
- name: postgres | tasks | extension | PostgREST | install get latest version
block:
- name: postgres | tasks | extension | PostgREST | get tags | get latest restic tags from github API
uri:
url: https://api.github.com/repos/PostgREST/postgrest/releases/latest
method: GET
status_code: 200
register: github_json_response
- name: postgres | tasks | extension | PostgREST | get tags | parsing github api response and set PostgREST version
set_fact:
postgrest_version: "{{ github_json_response.json.tag_name }}"
when: postgrest_version == 'latest'
- name: postgres | tasks | extension | PostgREST | get tags | show version selected
debug:
var: postgrest_version
- name: postgres | tasks | extension | PostgREST | create directory tree | PostgREST/
ansible.builtin.file:
path: /opt/PostgREST/
state: directory
mode: '0755'
- name: postgres | tasks | extension | PostgREST | create directory tree | tar_archive
ansible.builtin.file:
path: /opt/PostgREST/tar_archive
state: directory
mode: '0755'
- name: postgres | tasks | extension | PostgREST | create directory tree | "postgrest-{{postgrest_version}}"
ansible.builtin.file:
path: /opt/PostgREST/postgrest-{{postgrest_version}}/
state: directory
mode: '0755'
- name: postgres | tasks | extension | PostgREST | create directory tree | create /etc/postgrest/ configuration directory
ansible.builtin.file:
path: /etc/postgrest/
state: directory
mode: '0755'
- name: postgres | tasks | extension | PostgREST | check if "postgrest-{{postgrest_version}}-linux-static-x64.tar.xz exist"
stat:
path: /opt/PostgREST/postgrest-{{postgrest_version}}-linux-static-x64.tar.xz
register: postgrest_archive_exist
- name: postgres | tasks | extension | PostgREST | Download binary "postgrest-{{postgrest_version}}-linux-static-x64.tar.xz"
get_url:
url: https://github.com/PostgREST/postgrest/releases/download/{{ postgrest_version }}/postgrest-{{postgrest_version}}-linux-static-x64.tar.xz
dest: /opt/PostgREST/postgrest-{{postgrest_version}}-linux-static-x64.tar.xz
when: not postgrest_archive_exist.stat.exists
- name: postgres | tasks | extension | PostgREST | Unarchive "postgrest-{{postgrest_version}}-linux-static-x64.tar.xz"
ansible.builtin.unarchive:
src: /opt/PostgREST/postgrest-{{postgrest_version}}-linux-static-x64.tar.xz
dest: /opt/PostgREST/postgrest-{{postgrest_version}}/
remote_src: yes
- name: postgres | tasks | extension | PostgREST | create directory tree | create symlink to latest version
ansible.builtin.file:
src: /opt/PostgREST/postgrest-{{postgrest_version}}/postgrest
dest: /opt/PostgREST/postgrest_current
state: link
mode: '0755'
notify:
- restarted postgrest
- name: postgres | tasks | extension | PostgREST | create systemd service
ansible.builtin.template:
dest: /etc/systemd/system/postgrest.service
src: installation/postgrest.service.j2
notify:
- reloaded postgrest
- name: postgres | tasks | extension | PostgREST | create PostgREST configuration file
ansible.builtin.template:
src: installation/postgrest.conf.j2
dest: /etc/postgrest/postgrest.conf
mode: '0644'
owner: postgres
group: postgres
notify:
- restarted postgrest

View File

@ -0,0 +1,51 @@
- name: postgres | tasks | extension| pg_graphql | install requirements
dnf:
name:
- '@Development tools'
- git
- python2
- cmake
- postgresql{{ postgres_version }}-devel.x86_64
state: present
- name: postgres | tasks | extension| pg_graphql | install graphql/libgraphqlparser | clone code from github
ansible.builtin.git:
repo: https://github.com/graphql/libgraphqlparser.git
dest: /opt/libgraphqlparser
- name: postgres | tasks | extension| pg_graphql | install graphql/libgraphqlparser | cmake
ansible.builtin.command: cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .
args:
chdir: /opt/libgraphqlparser/
creates: /opt/libgraphqlparser/libgraphqlparser.so
- name: postgres | tasks | extension| pg_graphql | install graphql/libgraphqlparser | make
ansible.builtin.command: make
args:
chdir: /opt/libgraphqlparser/
creates: /opt/libgraphqlparser/libgraphqlparser.so
- name: postgres | tasks | extension| pg_graphql | install graphql/libgraphqlparser | make install
ansible.builtin.command: make install
args:
chdir: /opt/libgraphqlparser/
creates: /usr/local/lib/libgraphqlparser.so
- name: postgres | tasks | extension| pg_graphql | install graphql/pg_graphql | clone code from github
ansible.builtin.git:
repo: https://github.com/supabase/pg_graphql.git
dest: /opt/pg_graphql
- name: postgres | tasks | extension| pg_graphql | install graphql/pg_graphql | make
ansible.builtin.command: make install
environment:
PATH: "/usr/pgsql-{{postgres_version}}/bin/:{{ ansible_env.PATH }}"
args:
chdir: /opt/pg_graphql
creates: /opt/pg_graphql/pg_graphql.so
- name: "postgres | tasks | extension| pg_graphql | install graphql/pg_graphql | create link to /usr/pgsql-{{ postgres_version }}/lib/libgraphqlparser.so"
ansible.builtin.file:
src: /usr/lib/libgraphqlparser.so
dest: "/usr/pgsql-{{ postgres_version }}/lib/libgraphqlparser.so"
state: link

View File

@ -1,10 +1,10 @@
- name: postgres | install | extension | timescale | add timescale repo - name: postgres | tasks | extension| timescale | install | add timescale repo
ansible.builtin.template: ansible.builtin.template:
src: installation/timescale.repo.j2 src: installation/timescale.repo.j2
dest: /etc/yum.repos.d/timescale_timescaledb.repo dest: /etc/yum.repos.d/timescale_timescaledb.repo
- name: postgres | install | install postgresql - name: postgres | tasks | extension| timescale | install | install timescaledb extension
dnf: dnf:
name: name:
- timescaledb-2-postgresql-{{postgres_version}} - timescaledb-2-postgresql-{{postgres_version}}

View File

@ -0,0 +1,3 @@
db-uri = "{{postgrest_db_uri}}"
db-schemas = "{{ postgrest_db_schemas }}"
db-anon-role = "{{ postgrest_db_anon_role }}"

View File

@ -0,0 +1,12 @@
[Unit]
Description=REST API for any PostgreSQL database
After=postgresql.service
[Service]
User=postgrest
Group=postgrest
ExecStart=/opt/PostgREST/postgrest_current /etc/postgrest/postgrest.conf
ExecReload=/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=multi-user.target