From bd1808560cdda24207987140532948209d0d9352 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 21 Jul 2016 14:58:46 +0200 Subject: [PATCH] library/roles/smartgears/r_connector: Role that installs the smartgears r-connector. library/roles/smartgears/smartgears-nginx-frontend/templates: nginx virtualhosts for the rstudio servers. --- smartgears/r_connector/defaults/main.yml | 12 ++++++++ smartgears/r_connector/tasks/main.yml | 29 +++++++++++++++++++ smartgears/r_connector/templates/r-web.xml.j2 | 29 +++++++++++++++++++ smartgears/r_connector/templates/rusersadd.j2 | 19 ++++++++++++ .../rstudio-dev.d4science.org-virtualhost.j2 | 27 +++++++++++++++++ .../rstudio.d4science.org-virtualhost.j2 | 1 + 6 files changed, 117 insertions(+) create mode 100644 smartgears/r_connector/defaults/main.yml create mode 100644 smartgears/r_connector/tasks/main.yml create mode 100644 smartgears/r_connector/templates/r-web.xml.j2 create mode 100755 smartgears/r_connector/templates/rusersadd.j2 create mode 100644 smartgears/smartgears-nginx-frontend/templates/rstudio-dev.d4science.org-virtualhost.j2 create mode 120000 smartgears/smartgears-nginx-frontend/templates/rstudio.d4science.org-virtualhost.j2 diff --git a/smartgears/r_connector/defaults/main.yml b/smartgears/r_connector/defaults/main.yml new file mode 100644 index 00000000..51e5d7ac --- /dev/null +++ b/smartgears/r_connector/defaults/main.yml @@ -0,0 +1,12 @@ +--- +gcube_repository: 'gcube-staging' +r_connector_install: False +r_connector_ver: 2.0.1-4.0.0-128766 +r_connector_name: r-connector +r_connector_filename: '{{ r_connector_name }}-{{ r_connector_ver }}.war' +r_connector_url: 'http://maven.research-infrastructures.eu/nexus/content/repositories/{{ gcube_repository }}/org/gcube/data/analysis/{{ r_connector_name }}/{{ r_connector_ver}}/{{ r_connector_filename }}' +r_connector_war_file: '{{ r_connector_name }}.war' +r_connector_usershome: /home/ +r_connector_userconfig: userconfig.csv +r_connector_adduserscript: /usr/local/bin/rusersadd +r_connector_rstudio_cookie_key: /var/lib/rstudio-server/secure-cookie-key diff --git a/smartgears/r_connector/tasks/main.yml b/smartgears/r_connector/tasks/main.yml new file mode 100644 index 00000000..438336d0 --- /dev/null +++ b/smartgears/r_connector/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- block: + + - name: Remove the installed R connector before upgrading + file: dest={{ item }} state=absent + with_items: + - '{{ smartgears_instance_path }}/webapps/r-connector' + - '{{ smartgears_instance_path }}/webapps/r-connector.war' + when: smartgears_upgrade or not r_connector_install + + - name: Get the R connector war file + get_url: url={{ ckan_connector_url }} dest={{ smartgears_instance_path }}/webapps/{{ ckan_connector_war_file }} + + - name: Unpack the R connector war file + shell: mkdir {{ smartgears_instance_path }}/webapps/r-connector ; cd {{ smartgears_instance_path }}/webapps/r-connector ; jar xf {{ smartgears_instance_path }}/webapps/{{ ckan_connector_war_file }} + args: + creates: '{{ smartgears_instance_path }}/webapps/r-connector/WEB-INF/web.xml' + + - name: Obtain the permission to read the Rstudio secure cookie key + file: dest={{ r_connector_rstudio_cookie_key }} mode=640 group={{ smartgears_user }} + + - name: Install the R connector web.xml template + template: src=r-web.xml.j2 dest={{ smartgears_instance_path }}/webapps/r-connector/WEB-INF/web.xml mode=0440 + notify: Restart smartgears + + become: True + become_user: '{{ smartgears_user }}' + when: r_connector_install + tags: [ 'smartgears', 'r_connector', 'tomcat' ] diff --git a/smartgears/r_connector/templates/r-web.xml.j2 b/smartgears/r_connector/templates/r-web.xml.j2 new file mode 100644 index 00000000..93d69ca6 --- /dev/null +++ b/smartgears/r_connector/templates/r-web.xml.j2 @@ -0,0 +1,29 @@ + + + usersHome + {{ r_connector_usershome }} + + + filename + {{ r_connector_userconfig }} + + + addUserScript + {{ r_connector_adduserscript }} + + + storedKeyPath + {{ r_connector_rstudio_cookie_key }} + + + rStudioAddress + {{ ansible_fqdn }} + + + org.gcube.data.analysis.rconnector.RConnector + + + org.gcube.data.analysis.rconnector.RConnector + /gcube/service/* + + diff --git a/smartgears/r_connector/templates/rusersadd.j2 b/smartgears/r_connector/templates/rusersadd.j2 new file mode 100755 index 00000000..9a65de89 --- /dev/null +++ b/smartgears/r_connector/templates/rusersadd.j2 @@ -0,0 +1,19 @@ +#!/bin/bash + +USER="$1" +HDIR="{{ r_connector_usershome }}/$USER" + +if [ -d $HDIR ] ; then + #echo "user dir exist" + exit 0 +else + if id -u $USER >/dev/null 2>&1 + then + #"echo "ldap user first login" + /bin/su - $USER + exit 0 + else + #echo "user does not exist and is not ldap" + /usr/sbin/useradd -m -s /bin/false $USER + fi +fi diff --git a/smartgears/smartgears-nginx-frontend/templates/rstudio-dev.d4science.org-virtualhost.j2 b/smartgears/smartgears-nginx-frontend/templates/rstudio-dev.d4science.org-virtualhost.j2 new file mode 100644 index 00000000..3e7b1442 --- /dev/null +++ b/smartgears/smartgears-nginx-frontend/templates/rstudio-dev.d4science.org-virtualhost.j2 @@ -0,0 +1,27 @@ +server { + listen {{ http_port }}; + server_name {{ ansible_fqdn }}; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + proxy_read_timeout 600; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $schema; + proxy_set_header Host $http_host; + proxy_redirect off; + +{% for instance in tomcat_m_instances %} +{% for context in instance.app_contexts %} + location /{{ context }} { + proxy_pass http://localhost:{{ item.http_port }}/{{ context }}; + } +{% endfor %} +{% endfor %} + location / { + proxy_pass http://localhost:{{ rstudio_http_port }}/; + } + +} + diff --git a/smartgears/smartgears-nginx-frontend/templates/rstudio.d4science.org-virtualhost.j2 b/smartgears/smartgears-nginx-frontend/templates/rstudio.d4science.org-virtualhost.j2 new file mode 120000 index 00000000..4ebf333a --- /dev/null +++ b/smartgears/smartgears-nginx-frontend/templates/rstudio.d4science.org-virtualhost.j2 @@ -0,0 +1 @@ +rstudio-dev.d4science.org-virtualhost.j2 \ No newline at end of file