-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostgreSQL integration #11
Changes from 2 commits
bf26fe6
555e70d
ef2b37c
2d892ad
e0ec6ac
72f698b
2b5a25e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
- 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 == 'PostgreSQL' | ||
|
||
- 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: | ||
## 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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want this setting? Arent we configuring the database on our own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried again: for PostgreSQL, when I set this to
(and I tried again with postgresql or PostgreSQL for sympa parameter db_type, and that's the same). For MySQL, when I tried yesterday there was no difference wether I put true or false. I'll try to figure out what is the difference between PostgreSQL and MySQL installation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm too puzzled with this dbconfig parameter. I think my initial interpretation was right: seeing
One strange thing is that I don't find any reference to In order to avoid staying stucked, I propose you to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible solution here. I'll test again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Eureka! Yes, it did! |
||
## 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: | ||
|
@@ -173,3 +171,5 @@ | |
minute: "0" | ||
hour: "2" | ||
job: "/usr/lib/sympa/bin/sympa.pl --reload_list_config" | ||
|
||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
## MySQL configuration for sympa | ||
|
||
- name: check MySQL installation | ||
Scriptkiddi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
block: | ||
- name: Gather installed packages | ||
package_facts: | ||
manager: auto | ||
|
||
- name: check if MySQL is installed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please start with a capital letter |
||
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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
success_msg: "MySQL package found. We can continue!" | ||
when: not sympa_install_db_package | ||
|
||
- 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 | ||
|
||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are those dots for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See hereafter. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
## PostgreSQL installation and configuration for sympa | ||
|
||
- name: check PostgreSQL installation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please start with a capital Letter |
||
block: | ||
- name: Gather installed packages | ||
package_facts: | ||
manager: auto | ||
|
||
- name: check if postgres is installed | ||
Scriptkiddi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. English please :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry... copy/paste... :) |
||
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 } | ||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are those dots for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's YAML syntax for the end of a YAML section. It's not needed by Ansible, but I prefer to stick to the upstream syntax over Ansible pidgin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use lowercase strings without a space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this variables is there to set a debconf parameter of
select
type. When you install sympa manually, and after checking the debconf db withdebconf-get-selections
it clearly proposes "Other" and "Apache 2".I did some test, pre-setting the parameter with:
trying with
<value>
set toOther
,other
,apache2
,Apache 2
, etc.Without changing debconf priorities, when setting the value to
Other
it silently preserves this value. When setting other values, it silently overwrites to the default valueApache 2
.So I think that there, we have to stick to the exact spelling proposed for the two debconf
select
options.BTW, I struggled a lot with sympa debconf parameter. Sympa has a quite peculiar behaviour: most of the parameters are low o medium priority (so they aren't asked for), several are "internal", and most of all, they seem to be heavily overwritten at installation with default values, eventually built from linux hostname.