From 5eaafe1030956eb93f2d2519657dc72a17645fab Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Wed, 17 Oct 2018 00:11:16 -0400 Subject: [PATCH] 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 --- defaults/main.yml | 1 + tasks/install/pip.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index e3c46e0..640da16 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/install/pip.yml b/tasks/install/pip.yml index 7cb4c38..90bc987 100644 --- a/tasks/install/pip.yml +++ b/tasks/install/pip.yml @@ -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 }}"