-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible-rstudio.yaml
79 lines (79 loc) · 3.93 KB
/
ansible-rstudio.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
- name: Building and running RStudio container
hosts: localhost
vars_prompt:
- name: R_version
prompt: "Enter the R version you require (supported versions are 3.6.3 and >= 4.0.0) - ensure it is available as a tag at https://hub.docker.com/r/rocker/tidyverse/tags"
private: no
- name: R_tools
prompt: "Enter the R package tool you require as a space-separated list if more than one, e.g. tool1 tool2 tool3. If irrelevant, just press enter"
private: no
- name: BiocManager_tools
prompt: 'Enter the BiocManager tool you require, in the format (c(\"tool\")), as a comma-separated list if more than one, e.g. (c(\"tool1\",\"tool2\",\"tool3\")). If irrelevant, just press enter'
private: no
- name: container_name
prompt: "Give the container a name (no capitals) (blank not accepted)"
private: no
- name: container_version
prompt: "Give the container a version number"
private: no
- name: rstudio_password
prompt: "Give a simple password for your RStudio session, e.g. abc"
private: no
- name: ssh_key_path
prompt: "Enter the path to your ssh private key for this Nimbus instance on your local computer, e.g. ~/.ssh/id_rsa.key"
private: no
tasks:
- name: Print R version number
shell: echo {{ R_version }}
register: R_version_number
- name: Dockerfile changes for R_version == 3.6.3
shell: |
cp Dockerfile Dockerfile-{{ container_name }}_{{ container_version }}
echo "RUN mkdir /home/rstudio/library \
&& echo 'myPaths <- .libPaths(); myPaths <- c(myPaths, \"/home/rstudio/library\"); .libPaths(myPaths)' >> /usr/local/lib/R/library/base/R/Rprofile" >> Dockerfile-{{ container_name }}_{{ container_version }}
become: yes
when: R_version_number.stdout == "3.6.3"
- name: Dockerfile changes for R_version != 3.6.3
shell: |
cp Dockerfile Dockerfile-{{ container_name }}_{{ container_version }}
echo "RUN sed -i '1488s|true|false|' /usr/lib/rstudio-server/resources/schema/user-prefs-schema.json" >> Dockerfile-{{ container_name }}_{{ container_version }} #to uncheck memory usage showing up
when: R_version_number.stdout != "3.6.3"
- name: Completing the Dockerfile
shell: |
sed -i "s|tidyverse:4.0.3|tidyverse:{{ R_version }}|g" Dockerfile-{{ container_name }}_{{ container_version }}
sed -i "s|caTools|caTools {{ R_tools }}|g" Dockerfile-{{ container_name }}_{{ container_version }}
echo "RUN R -e 'library(BiocManager)' \
&& R -e 'BiocManager::install({{ BiocManager_tools }})'" >> Dockerfile-{{ container_name }}_{{ container_version }}
args:
warn: false
- name: Building the Docker image
command: docker build -f Dockerfile-{{ container_name }}_{{ container_version }} -t {{ container_name }}:{{ container_version }} .
become: yes
- name: Building the Singularity container
command: singularity pull docker-daemon:{{ container_name }}:{{ container_version }}
become: yes
args:
creates: "{{ container_name }}_{{ container_version }}.sif"
- name: Running the container as an interactive RStudio session
script: run_rstudio.sh '{{ ssh_key_path }}' '{{ rstudio_password}}'
register: result_rstudio
- name: Create a data folder
command: mkdir /data
become: yes
args:
creates: /data
- name: Change ownership of data folder
command: chown ubuntu:ubuntu /data
become: yes
args:
warn: false
- name: Create RStudio server folder
command: mkdir -p /tmp/rstudio-server
args:
creates: /tmp/rstudio-server
- name: Run rserver command
shell: PASSWORD='{{ rstudio_password }}' singularity exec -B /tmp/rstudio-server:/var/lib/rstudio-server -B /tmp/rstudio-server:/var/run/rstudio-server -B /data:/home {{ container_name }}_{{ container_version }}.sif rserver --www-port 8787 --www-address 0.0.0.0 --auth-none=0 --auth-pam-helper-path=pam-helper &
- name: Print RStudio server instructions
debug:
var: result_rstudio.stdout_lines