From 8857b3054c11b6b0ed46d889eefbdcbad7e71463 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Fri, 1 Jun 2018 17:31:17 -0400 Subject: [PATCH] Add support for installing from source This provides the ability to install from source either on the local filesystem or from pypi. Change-Id: I883bf88638d6d4de1965f1863a4c401e58ea0126 --- defaults/main.yml | 21 +++++++++-- tasks/install/pip.yml | 61 +++++++++++++++++++++++++++++++ tasks/main.yml | 34 +---------------- templates/apache_mod_wsgi.conf.j2 | 6 +-- 4 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 tasks/install/pip.yml diff --git a/defaults/main.yml b/defaults/main.yml index e1491dd..f4ef6c5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,10 +18,23 @@ ara: params: - # If ARA should be installed inside a virtualenv - virtualenv: true - # Location where the virtualenv should be installed - virtualenv_path: /opt/ara-venv + install: + # The method used to install ARA ('pip' or 'distribution') + method: pip + pip: + # If ARA should be installed inside a virtualenv + virtualenv: true + # Location where the virtualenv should be installed + virtualenv_path: /opt/ara-venv + # Method to install ARA with pip ('pypi' or 'source') + method: pypi + # When installing from source, location of the repository + # When installing from a source on the filesystem, only specify the path to the repository + source: git+https://git.openstack.org/openstack/ara + # When installing from pypi, version to install (ex: '0.15.0') + # When installing from source, ref to the commit, tag or branch to install + # Defaults to the latest version on PyPi or the master branch when installing from source + version: config: database: "sqlite:////var/lib/ara/ansible.sqlite" # Host to listen on for embedded server, apache or nginx diff --git a/tasks/install/pip.yml b/tasks/install/pip.yml new file mode 100644 index 0000000..baa3cb5 --- /dev/null +++ b/tasks/install/pip.yml @@ -0,0 +1,61 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Install required dependencies + become: true + package: + name: "{{ required_packages }}" + state: "present" + +# Debian/Ubuntu has a package for python-pip, RHEL and CentOS do not. +# TODO: Fedora actually has a package for python-pip. +- name: Install pip for Red Hat distributions + become: true + easy_install: + name: pip + state: present + +# Need to make sure setuptools is up to date +- name: Initialize virtualenv with up-to-date setuptools + become: true + pip: + name: setuptools + state: latest + virtualenv: "{{ ara.params.install.pip.virtualenv_path }}" + when: ara.params.install.pip.virtualenv | bool + +- name: Install ARA with pip + become: true + vars: + # Manage that the 'version' argument doesn't work when installing from source + pkg_name: | + {%- if ara.params.install.pip.method == 'source' -%} + {{- ara.params.install.pip.source }}@{{ ara.params.install.pip.version | default('master') -}} + {%- else -%} + ara + {%- endif -%} + pip: + name: "{{ pkg_name }}" + version: "{{ ara.params.install.pip.version | default(omit, True) }}" + state: present + virtualenv: "{{ ara.params.install.pip.virtualenv | bool | ternary(ara.params.install.pip.virtualenv_path, omit) }}" + +- name: Suffix the virtualenv bin directory to PATH + set_fact: + path_with_virtualenv: "{{ ara.params.install.pip.virtualenv_path }}/bin:{{ ansible_env.PATH }}" + when: ara.params.install.pip.virtualenv | bool diff --git a/tasks/main.yml b/tasks/main.yml index 02023dd..7ca198f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -29,38 +29,8 @@ - ara_override is defined - ara_override is mapping -- name: Install required dependencies - become: true - package: - name: "{{ required_packages }}" - state: "present" - -- name: Install pip - become: true - easy_install: - name: pip - state: present - -# Need to make sure setuptools is up to date -- name: Initialize virtualenv with up-to-date setuptools - become: true - pip: - name: setuptools - state: latest - virtualenv: "{{ ara.params.virtualenv_path }}" - when: ara.params.virtualenv | bool - -- name: Install ARA with pip - become: true - pip: - name: ara - state: present - virtualenv: "{{ ara.params.virtualenv | bool | ternary(ara.params.virtualenv_path, omit) }}" - -- name: Suffix the virtualenv bin directory to PATH - set_fact: - path_with_virtualenv: "{{ ara.params.virtualenv_path }}/bin:{{ ansible_env.PATH }}" - when: ara.params.virtualenv | bool +- name: Include ARA installation + include_tasks: "install/{{ ara.params.install.method }}.yml" - name: Create user for ARA become: true diff --git a/templates/apache_mod_wsgi.conf.j2 b/templates/apache_mod_wsgi.conf.j2 index 5083f52..ac561b7 100644 --- a/templates/apache_mod_wsgi.conf.j2 +++ b/templates/apache_mod_wsgi.conf.j2 @@ -6,11 +6,11 @@ CustomLog {{ apache_log_path }}/ara-access.log combined SetEnv ANSIBLE_CONFIG /etc/ara/ara.cfg - {% if ara.params.virtualenv -%} + {% if ara.params.install.pip.virtualenv -%} SetEnv ARA_WSGI_USE_VIRTUALENV 1 - SetEnv ARA_WSGI_VIRTUALENV_PATH {{ ara.params.virtualenv_path }} + SetEnv ARA_WSGI_VIRTUALENV_PATH {{ ara.params.install.pip.virtualenv_path }} - WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 python-home={{ ara.params.virtualenv_path }} + WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 python-home={{ ara.params.install.pip.virtualenv_path }} {% else -%} WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 {% endif -%}