Skip to content

Commit

Permalink
preparing pg integration, mysql check and optional installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ulvida committed Feb 24, 2020
1 parent bad09b1 commit bf26fe6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 30 deletions.
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ sympa_template_lists: []
# ssl: true
# queue_transport: sympa
# 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_name: sympa
sympa_db_host: localhost
sympa_db_port: 3306
Expand Down Expand Up @@ -113,4 +117,5 @@ sympa_default_home: home
sympa_edit_list: owner
sympa_ldap_force_canonical_email: 1
sympa_review_page_size: 25
sympa_webserver_type: Other # 'Other' or 'Apache 2'
sympa_web_page_title: Mailing lists service
50 changes: 20 additions & 30 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
- name: Set database to mysql
debconf:
name: sympa
question: sympa/database-type
value: mysql
vtype: select
---
## Sympa configuration main tasks file

- name: Set webserver to other
debconf:
name: sympa
question: wwsympa/webserver_type
value: Other
vtype: select
- name: MySQL/MariaDB configuration
include_tasks: mysql.yml
when: sympa_db_type == 'mysql'

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

- name: "Set dbconfig-install to no"
- name: Set debconf options for sympa
debconf:
name: sympa
question: sympa/dbconfig-install
value: no
vtype: boolean
changed_when: false

- name: Create a new database with name '{{ sympa_db_name }}'
mysql_db:
name: "{{ sympa_db_name }}"
encoding: utf8

- name: Create DB user '{{ sympa_db_user }}'
mysql_user:
name: "{{ sympa_db_user }}"
password: "{{ sympa_db_password | mandatory }}"
priv: '{{ sympa_db_name }}.*:ALL,GRANT'
no_log: True
name: "{{ item.name }}"
question: "{{ item.question }}"
value: "{{ item.value }}"
vtype: "{{ item.vtype }}"
loop:
- { name: 'sympa', question: 'sympa/database-type', value: '{{ sympa_db_type }}' , vtype: select }
- { name: 'sympa', question: 'sympa/dbconfig-install', value: 'true' , vtype: boolean }
- { name: 'sympa', question: 'wwsympa/webserver_type', value: '{{ sympa_webserver_type }}' , vtype: select }

- name: Create sympa dir
file:
Expand Down Expand Up @@ -173,3 +161,5 @@
minute: "0"
hour: "2"
job: "/usr/lib/sympa/bin/sympa.pl --reload_list_config"

...
53 changes: 53 additions & 0 deletions tasks/mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
## MySQL configuration for sympa

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

- name: check if MySQL is installed
assert:
that: >
ansible_facts.packages['default-mysql-server'] is defined or
ansible_facts.packages['mysql-server'] is defined or
ansible_facts.packages['mariadb-server-10.1'] is defined
## The last condition could be replaced by a jinja2 json_query filter to match any version
fail_msg: "No MySQL pachage found. We stop, because we can't install sympa without its database. Sorry."
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:
- default-mysql-server
- python-dev
- default-libmysqlclient-dev
state: present
when: sympa_install_db_package

- name: Install pip, if not yet installed
apt:
name: python-pip
state: present

- name: install mysqlclient pip module, if not yet installed
pip:
name: mysqlclient
state: present

- name: Create a new database with name '{{ sympa_db_name }}'
mysql_db:
name: "{{ sympa_db_name }}"
encoding: utf8

- name: Create DB user '{{ sympa_db_user }}'
mysql_user:
name: "{{ sympa_db_user }}"
password: "{{ sympa_db_password | mandatory }}"
priv: '{{ sympa_db_name }}.*:ALL,GRANT'
no_log: True

...
4 changes: 4 additions & 0 deletions tasks/postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
## PostgreSQL configuration for sympa

...

0 comments on commit bf26fe6

Please sign in to comment.