Skip to content

Commit

Permalink
PostgreSQL integration. For first PR of #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ulvida committed Feb 24, 2020
1 parent bf26fe6 commit 555e70d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ sympa_template_lists: []
# bouncequeue_transport: sympabounce

## Database variables
sympa_db_type: mysql # mysql or pgsql
sympa_install_db_package: false # yes for this role to install mysql or postgres, no if installed elsewhere / TODO: not yet working for MySQL
sympa_db_type: mysql # mysql or PostgreSQL
sympa_install_db_package: false # yes for this role to install mysql or postgres, no if installed elsewhere
sympa_db_name: sympa
sympa_db_host: localhost
sympa_db_port: 3306
Expand Down
12 changes: 11 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- name: PostgreSQL configuration
include_tasks: postgresql.yml
when: sympa_db_type == 'pgsql'
when: sympa_db_type == 'PostgreSQL'

- name: Set debconf options for sympa
debconf:
Expand All @@ -16,10 +16,20 @@
value: "{{ item.value }}"
vtype: "{{ item.vtype }}"
loop:
## set the database type
- { name: 'sympa', question: 'sympa/database-type', value: '{{ sympa_db_type }}' , vtype: select }
## Configure the database at sympa installation with dbconfig
- { name: 'sympa', question: 'sympa/dbconfig-install', value: 'true' , vtype: boolean }
## Set the sympa database name
- { name: 'sympa', question: 'sympa/db/dbname', value: '{{ sympa_db_name }}' , vtype: string }
## Set the sympa database user
- { name: 'sympa', question: 'sympa/db/app-user', value: '{{ sympa_db_user }}' , vtype: string }
## Use the localhost for database (and not a distant host to define)
- { name: 'sympa', question: 'sympa/remote/host', value: 'localhost' , vtype: select }
## Set the webserver type
- { name: 'sympa', question: 'wwsympa/webserver_type', value: '{{ sympa_webserver_type }}' , vtype: select }


- name: Create sympa dir
file:
path: "/etc/sympa/sympa"
Expand Down
3 changes: 1 addition & 2 deletions tasks/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
## MySQL configuration for sympa

- name: check mysql installation
- name: check MySQL installation
block:
- name: Gather installed packages
package_facts:
Expand All @@ -18,7 +18,6 @@
success_msg: "MySQL package found. We can continue!"
when: not sympa_install_db_package

## TODO: minimal installation of MySQL for sympa. This single task is not enough
- name: Install MySQL packages
apt:
name:
Expand Down
63 changes: 62 additions & 1 deletion tasks/postgresql.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
---
## PostgreSQL configuration for sympa
## PostgreSQL installation and configuration for sympa

- name: check PostgreSQL installation
block:
- name: Gather installed packages
package_facts:
manager: auto

- name: check if postgres is installed
assert:
that: ansible_facts.packages['postgresql'] is defined
fail_msg: "No PostgreSQL pachage found. We stop, because we can't install sympa without its database. Sorry."
success_msg: "PostgreSQL package found. We can continue!"
when: not sympa_install_db_package

- name: Install PostgreSQL
apt:
state: present
update_cache: yes
cache_valid_time: 3600
name:
- postgresql
- postgresql-contrib
- libpq-dev
- python-psycopg2
- dbconfig-pgsql
when: sympa_install_db_package
tags: postgresql

- name: Create sympa database
become: true
become_user: postgres
postgresql_db:
name: "{{ sympa_db_name }}"
encoding: UTF-8
lc_collate: es_UY.UTF-8
lc_ctype: es_UY.UTF-8
template: template0
state: present
tags: postgresql

- name: Create sympa user with access to the database
become: true
become_user: postgres
postgresql_user:
db: "{{ sympa_db_name }}"
name: "{{ sympa_db_user }}"
password: "{{ sympa_db_password | mandatory }}"
priv: ALL
state: present
tags: postgresql

## Debconf keys for sympa database

- name: Definir opciones debconf de sympa, relativas a la base PostgreSQL
debconf:
name: "{{ item.name }}"
question: "{{ item.question }}"
value: "{{ item.value }}"
vtype: "{{ item.vtype }}"
loop:
## Set the sympa database password
- { name: 'sympa', question: 'sympa/pgsql/app-pass', value: '{{ sympa_db_password | mandatory }}' , vtype: password }
...
2 changes: 1 addition & 1 deletion templates/sympa.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ parsed_family_files {{ sympa_parsed_family_files }}
## db_type
## Type of the database (mysql|Pg|Oracle|Sybase|SQLite)
## Be careful to the case
db_type mysql
db_type {{ sympa_db_type }}

## db_name
## Name of the database
Expand Down

0 comments on commit 555e70d

Please sign in to comment.