Automatically install pymysql or psycopg2 if necessary

If a user is supplying a pymysql or psycopg2 connection string, the
necessary driver needs to be installed before it can be used.

Change-Id: I4655c9a39fea6a43f7e579f099d61836577202f0
This commit is contained in:
David Moreau Simard 2018-10-17 00:11:16 -04:00
parent c51366f722
commit 5eaafe1030
No known key found for this signature in database
GPG Key ID: CBEB466764A9E621
2 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,7 @@ ara:
# Defaults to the latest version on PyPi or the master branch when installing from source
version:
config:
# If pymysql or psycopg2 are found in the connection string, the role will install the necessary driver
database: "sqlite:////var/lib/ara/ansible.sqlite"
# Host to listen on for embedded server, apache or nginx
host: 127.0.0.1

View File

@ -55,6 +55,22 @@
state: present
virtualenv: "{{ ara.install.pip.virtualenv | bool | ternary(ara.install.pip.virtualenv_path, omit) }}"
- name: Install pymysql with pip
become: true
pip:
name: pymysql
state: present
virtualenv: "{{ ara.install.pip.virtualenv | bool | ternary(ara.install.pip.virtualenv_path, omit) }}"
when: '"pymysql" in ara.config.database'
- name: Install psycopg2 with pip
become: true
pip:
name: psycopg2
state: present
virtualenv: "{{ ara.install.pip.virtualenv | bool | ternary(ara.install.pip.virtualenv_path, omit) }}"
when: '"psycopg2" in ara.config.database'
- name: Suffix the virtualenv bin directory to PATH
set_fact:
path_with_virtualenv: "{{ ara.install.pip.virtualenv_path }}/bin:{{ ansible_env.PATH }}"