Skip to content

Commit

Permalink
Update dbt7 roles to use AppImage
Browse files Browse the repository at this point in the history
  • Loading branch information
mw2q authored and hannahms committed Oct 18, 2023
1 parent 47d712c commit 1085de4
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 145 deletions.
48 changes: 12 additions & 36 deletions roles/setup_dbt7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,31 @@ This role is for installing DBT-7.

Following are the requirements of this role.
1. Ansible
2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository on
the systems.

## Role Variables

When executing the role via ansible these are the required variables:

* ***dbt7_pgdata***
* ***dbt7_version***

This variable is to be used to specify a custom PGDATA directory that DBT-7
will use separately from the default PGDATA that may be used in other
playbooks. Thus do not set this to a directory that may be used elsewhere.
You are not likely to use this unless you are testing specific source based
installations of PostgreSQL or doing any other highly customized testing with
logical or physical system configurations.
These playbooks can install any version of the DBT-7 AppImage that is
packaged from GitHub. See the following link for available versions:
https://github.com/osdldbt/dbt7/releases

* ***dbt7-version***
* ***have_tpcdsfile***

These playbooks can install any version of DBT-7 that is packaged from GitHub.
See the following link for available versions:
https://github.com/osdldbt/dbt7-packaging/releases

* ***have_tpcfile***

The is a boolean use for CI purposes where we cannot redistribute TPC code
This is a boolean used for CI purposes where we cannot redistribute TPC code
thus the CI system will not attempt to run the tasks specific for setting up
the TPC code.

* ***pg_version***

Postgres Versions supported are: 10, 11, 12, 13 and 14

* ***tpcfile***
* ***tpcdsfile***

This is the full path to the TPC-DS Tools zip file that must be downloaded by
the you, the user, per TPC EULA agreement. The TPC-DS Tools can be requested
at:
you, the user, per TPC EULA agreement. The TPC-DS Tools can be requested at:
https://www.tpc.org/tpc_documents_current_versions/current_specifications5.asp

These variables can be assigned in the `pre_tasks` definition of the
section: *How to include the `setup_dbt7` role in your Playbook*.
section.

## Example Playbook

Expand Down Expand Up @@ -74,7 +58,7 @@ Below is an example of how to include the `setup_dbt7` role:
```yaml
---
- hosts: all
name: Postgres deployment playbook for DBT-3
name: Postgres deployment playbook for DBT-7
become: yes
gather_facts: yes
any_errors_fatal: True
Expand All @@ -84,27 +68,19 @@ Below is an example of how to include the `setup_dbt7` role:
- edb_devops.edb_postgres
roles:
- role: setup_repo
when: "'setup_repo' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: install_dbserver
when: "'install_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: init_dbserver
when: "'init_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_dbt7
when: "'setup_dbt7' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: tuning
when: "'tuning' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
```

## Playbook execution examples

```bash
# To deploy community Postgres version 13 with the user centos
# To deploy community Postgres with the user centos
$ ansible-playbook playbook.yml \
-i inventory.yml \
-u centos \
--private-key <key.pem> \
--extra-vars="pg_version=13 pg_type=PG"
--extra-vars="pg_type=PG"
```

## License
Expand Down
14 changes: 9 additions & 5 deletions roles/setup_dbt7/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
dbt7_version: "0.4.1"
dbt7_pgdata: "/pgdata/dbt7/pgdata"
pg_version: 14
have_tpcfile: true
tpcfile: ""
dbt7_version: "0.5.0"
have_tpcdsfile: true
tpcdsfile: ""

# DBT-7 AppImage information
dbt7_appimage: "https://github.com/osdldbt/dbt7/releases/download/v{{ dbt7_version }}/dbt7-{{ dbt7_version }}-x86_64.AppImage"
dbt7_checksum: "{{ dbt7_appimage }}.sha256"
dbt7_path: "/usr/bin/dbt7"

# setting validate_only to true allows you to validate setup on an existing node
# use_validation flag applies to deployment configuration and validation after setup
Expand All @@ -15,3 +18,4 @@ supported_os:
- RedHat8
- Rocky8
- AlmaLinux8
- OracleLinux7
7 changes: 0 additions & 7 deletions roles/setup_dbt7/tasks/dbt7_configure_profile.yml

This file was deleted.

27 changes: 15 additions & 12 deletions roles/setup_dbt7/tasks/dbt7_install_packages.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
---

- name: Install additional supporting packages
ansible.builtin.package:
name:
- bison
- gcc
- bc
- byacc
- dejavu-fonts-common
- flex
- fontconfig
- fuse
- fuse-libs
- gcc
- make
- patch
- perf
- psmisc
- python3-docutils
- R-core
- sysstat
- tmux
- unzip
state: present
when: ansible_os_family == "RedHat"
become: true

- name: Install packages for DBT-7 Database
ansible.builtin.dnf:
name:
- 'https://github.com/osdldbt/dbt7-packaging/releases/download/v{{ dbt7_version }}/dbt7-{{ dbt7_version }}-1.el8.x86_64.rpm'
state: present
disable_gpg_check: true
when: ansible_os_family == "RedHat"
- name: Download DBT-7 AppImage
ansible.builtin.get_url:
url: "{{ dbt7_appimage }}"
checksum: "sha256:{{ dbt7_checksum }}"
dest: "{{ dbt7_path }}"
mode: '0755'
become: true
25 changes: 7 additions & 18 deletions roles/setup_dbt7/tasks/dbt7_tpc.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
---
- name: Check that 'tpcfile' is set to local TPC-H Tools location
- name: Check that 'tpcdsfile' is set to local TPC-H Tools location
ansible.builtin.fail:
msg: >-
The Ansible variable 'tpcfile' must be set to a locally downloaded copy
The Ansible variable 'tpcdsfile' must be set to a locally downloaded copy
of the TPC supplied TPC-H Tools from:
https://www.tpc.org/tpc_documents_current_versions/current_specifications5.asp
when: tpcfile|length < 1
when: tpcdsfile | length < 1

- name: Copy and unarchive TPC-H Tools to remote host
ansible.builtin.unarchive:
src: "{{ tpcfile }}"
src: "{{ tpcdsfile }}"
dest: "{{ pg_user_home }}"
become_user: "{{ pg_owner }}"

- name: Patch TPC-H Tools for PostgreSQL
ansible.posix.patch:
remote_src: true
src: "{{ item }}"
basedir: "{{ pg_user_home }}"
strip: 1
become_user: "{{ pg_owner }}"
loop:
- /usr/share/dbt7/dbt7-DSGen-software-code-3.2.0rc1.diff
- /usr/share/dbt7/dbt7-DSGen-software-code-3.2.0rc1-postgresql-queries.diff

- name: Build TPC-H Tools for PostgreSQL
community.general.make:
chdir: "{{ pg_user_home }}/DSGen-software-code-3.2.0rc1/tools"
- name: Build TPC-DS Tools for PostgreSQL
ansible.builtin.shell: >-
dbt7 build-dsgen {{ pg_user_home }}/DSGen-software-code-3.2.0rc1
become_user: "{{ pg_owner }}"
8 changes: 2 additions & 6 deletions roles/setup_dbt7/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

- name: Include TPC installation
ansible.builtin.include_tasks: dbt7_tpc.yml
when: have_tpcfile and not validate_only|bool
when: have_tpcdsfile and not validate_only|bool

- name: Include DBT-7 profile configuration
ansible.builtin.include_tasks: dbt7_configure_profile.yml
when: not validate_only|bool

- name: Include validate_setup_dbt7 tasks
- name: Include the validate_setup_dbt7 tasks
ansible.builtin.include_tasks: validate_setup_dbt7.yml
when: validate_only|bool or use_validation|bool
48 changes: 21 additions & 27 deletions roles/setup_dbt7/tasks/validate_setup_dbt7.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
---
# validate dbt7 package
- name: Set dbt7 package name
# validate dbt7 db packages installation
- name: Set dbt7_db_pkg_list
ansible.builtin.set_fact:
dbt7_package: 'dbt7'
dbt7_db_pkg_list: ['bc', 'byacc', 'dejavu-fonts-common', 'flex', 'fontconfig', 'fuse', 'fuse-libs', 'gcc', 'make', 'patch', 'perf', 'psmisc', 'sysstat', 'tmux', 'unzip']

- name: Gather the package facts
ansible.builtin.package_facts:
strategy: "all"

- name: Check that DBT7 packages have been installed
- name: Check that all packages in dbt7_db_pkg_list has been installed
ansible.builtin.assert:
that:
- "{{ ansible_facts.packages[dbt7_package] }} is defined"
fail_msg: "Package {{ dbt7_package }} has not been installed."
success_msg: "Package {{ dbt7_package }} has been installed."
- "{{ ansible_facts.packages[package] }} is defined"
fail_msg: "Package {{ package }} has not been installed."
success_msg: "Package {{ package }} has been installed."
loop: "{{ dbt7_db_pkg_list }}"
loop_control:
loop_var: package

# validate dbt7 user
- name: Run query to check dbt7 user is in pg_user
ansible.builtin.include_role:
name: manage_dbserver
tasks_from: execute_sql_scripts
vars:
pg_query:
- query: "Select * from pg_user where usename = '{{ pg_owner }}'"
db: "{{ pg_database }}"

- name: Set user_query_result with sql_query_output
ansible.builtin.set_fact:
user_query_result: "{{ sql_query_output }}"
# ensure the DBT-7 AppImage has been installed to the proper location
- name: Stat to dbt7_path
ansible.builtin.stat:
path: "{{ dbt7_path }}"
register: dbt7_path_stat
become: true

- name: Check if DBT7 postgres user was successfully created
- name: Check if DBT-7 AppImage was installed properly on DB
ansible.builtin.assert:
that:
- user_query_result.results[0].query_result[0]['usename'] == pg_owner
fail_msg: "DBT7 postgres user was not successfully created."
success_msg: "DBT7 postgres user was successfully created."
run_once: true
- dbt7_path_stat.stat['exists']|bool
fail_msg: "DBT-7 AppImage at {{ dbt7_path }} was not created properly"
success_msg: "DBT-7 AppImage at {{ dbt7_path }} was created successfully"

# reset variables
- name: Reset variables
ansible.builtin.set_fact:
dbt7_package: null
user_query_result: null
dbt7_db_pkg_list: null
dbt7_path_stat: null
19 changes: 0 additions & 19 deletions roles/setup_dbt7/templates/dbt7_profile

This file was deleted.

4 changes: 0 additions & 4 deletions roles/setup_dbt7/vars/DBaaS.yml

This file was deleted.

5 changes: 1 addition & 4 deletions roles/setup_dbt7/vars/EPAS.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---
pg_owner: "enterprisedb"
pg_port: "5444"
pg_superuser: "enterprisedb"
pg_instance_name: "main"
pg_data: "/var/lib/edb/as{{ pg_version }}/{{ pg_instance_name }}/data"
pg_user_home: "/var/lib/edb"
5 changes: 1 addition & 4 deletions roles/setup_dbt7/vars/PG.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---
pg_owner: "postgres"
pg_port: "5432"
pg_superuser: "postgres"
pg_instance_name: "main"
pg_data: "/var/lib/pgsql/{{ pg_version }}/{{ pg_instance_name }}/data"
pg_user_home: "/var/lib/pgsql"
3 changes: 1 addition & 2 deletions tests/cases/setup_dbt7/vars.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"use_hostname": false,
"pg_data": "/opt/pgdata",
"pg_wal": "/opt/pgwal",
"limit_file_path": "/etc/security/limits.conf",
"have_tpcfile": false
"have_tpcdsfile": false
}
18 changes: 17 additions & 1 deletion tests/tests/test_setup_dbt7.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@

def test_setup_dbt7_packages():
host = get_primary()
packages = ['dbt7']
packages = [
'bc',
'byacc',
'dejavu-fonts-common',
'flex',
'fontconfig',
'fuse',
'fuse-libs',
'gcc',
'make',
'patch',
'perf',
'psmisc',
'sysstat',
'tmux',
'unzip',
]

for package in packages:
assert host.package(package).is_installed, \
Expand Down

0 comments on commit 1085de4

Please sign in to comment.