-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathR_only.yml
More file actions
250 lines (218 loc) · 7.72 KB
/
Copy pathR_only.yml
File metadata and controls
250 lines (218 loc) · 7.72 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
---
- name: Install R, Rstudio, Rtools, and example packages
hosts: all
vars_files:
- config.yml
remote_user: "{{ username }}"
become: yes
connection: local
gather_facts: false
tasks:
- name: Install prerequisites for R
ansible.builtin.package:
name:
- software-properties-common
- dirmngr
- wget
- ca-certificates
- gnupg2
- apt-transport-https
- curl
state: present
update_cache: yes
- name: Remove old R GPG key if exists
ansible.builtin.file:
path: /usr/share/keyrings/r-project.gpg
state: absent
- name: Download R repository GPG key to temp file with proxy
ansible.builtin.shell: |
wget -e use_proxy=yes \
-e http_proxy="{{ http_proxy }}" \
-e https_proxy="{{ https_proxy }}" \
-O /tmp/r-key.asc \
https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc
args:
creates: /tmp/r-key.asc
environment:
http_proxy: "{{ http_proxy | default('') }}"
https_proxy: "{{ https_proxy | default('') }}"
register: wget_result
when: use_proxy
- name: Download R repository GPG key to temp file without proxy
ansible.builtin.shell: |
wget -O /tmp/r-key.asc \
https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc
args:
creates: /tmp/r-key.asc
register: wget_result
when: not use_proxy
- name: Verify key was downloaded
ansible.builtin.stat:
path: /tmp/r-key.asc
register: key_file
- name: Display download status
ansible.builtin.debug:
msg: "Key downloaded: {{ key_file.stat.exists }}, Size: {{ key_file.stat.size | default('N/A') }}"
- name: Convert GPG key to binary format
ansible.builtin.shell: |
cat /tmp/r-key.asc | gpg --dearmor -o /usr/share/keyrings/r-project.gpg
chmod 644 /usr/share/keyrings/r-project.gpg
when: key_file.stat.exists
register: gpg_result
- name: Verify GPG key was created
ansible.builtin.stat:
path: /usr/share/keyrings/r-project.gpg
register: gpg_key
- name: Display GPG key status
ansible.builtin.debug:
msg: "GPG key created: {{ gpg_key.stat.exists }}, Size: {{ gpg_key.stat.size | default('N/A') }}"
- name: Clean up temporary key file
ansible.builtin.file:
path: /tmp/r-key.asc
state: absent
- name: Get Ubuntu codename
ansible.builtin.command:
cmd: lsb_release -cs
register: ubuntu_codename
changed_when: false
- name: Add R repository with signed-by
ansible.builtin.copy:
content: |
deb [signed-by=/usr/share/keyrings/r-project.gpg] https://cloud.r-project.org/bin/linux/ubuntu {{ ubuntu_codename.stdout }}-cran40/
dest: /etc/apt/sources.list.d/cran.list
mode: '0644'
when: gpg_key.stat.exists
- name: Update apt cache with proxy
ansible.builtin.apt:
update_cache: yes
environment:
http_proxy: "{{ http_proxy | default('') }}"
https_proxy: "{{ https_proxy | default('') }}"
when: gpg_key.stat.exists and use_proxy
- name: Update apt cache without proxy
ansible.builtin.apt:
update_cache: yes
when: gpg_key.stat.exists and not use_proxy
- name: Install R base and development tools
ansible.builtin.package:
name:
- r-base
- r-base-dev
- build-essential
- libcurl4-openssl-dev
- libssl-dev
- libxml2-dev
- libfontconfig1-dev
- libharfbuzz-dev
- libfribidi-dev
- libfreetype6-dev
- libpng-dev
- libtiff5-dev
- libjpeg-dev
state: present
- name: Check R version
ansible.builtin.command:
cmd: R --version
register: r_version
changed_when: false
become: no
- name: Display R version
ansible.builtin.debug:
msg: "{{ r_version.stdout_lines[0] }}"
- name: Set library, configure and install packages for the user
hosts: all
vars_files:
- config.yml
remote_user: "{{ username }}"
vars:
actual_user: "{{ lookup('env', 'SUDO_USER') | default(username) }}"
become: true
become_user: "{{ actual_user }}"
connection: local
gather_facts: false
tasks:
- name: Create R library directory for user
ansible.builtin.file:
path: "{{ root_path }}/R/library"
state: directory
mode: '0755'
become: true
become_user: "{{ actual_user }}"
- name: Configure R to use proxy (if needed)
ansible.builtin.copy:
content: |
# R environment configuration
{% if http_proxy is defined and http_proxy != '' %}
options(
repos = c(CRAN = "https://cloud.r-project.org/"),
download.file.method = "libcurl",
HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version$platform, R.version$arch, R.version$os))
)
# Proxy settings
Sys.setenv(
http_proxy = "{{ http_proxy }}",
https_proxy = "{{ https_proxy }}",
HTTP_PROXY = "{{ http_proxy }}",
HTTPS_PROXY = "{{ https_proxy }}"
)
{% else %}
options(
repos = c(CRAN = "https://cloud.r-project.org/"),
download.file.method = "libcurl"
)
{% endif %}
# Set library path
.libPaths(c("{{ root_path }}/R/library", .libPaths()))
message("✓ R environment configured")
dest: "{{ root_path }}/.Rprofile"
mode: '0644'
become: true
become_user: "{{ actual_user }}"
when: use_proxy
- name: Install R packages (renv and ggplot2) with proxy
ansible.builtin.shell: |
R -e 'install.packages(c("renv", "ggplot2"), lib="{{ root_path }}/R/library", repos="https://cloud.r-project.org/")'
become: no
environment:
HOME: "{{ root_path }}"
R_LIBS_USER: "{{ root_path }}/R/library"
http_proxy: "{{ http_proxy | default('') }}"
https_proxy: "{{ https_proxy | default('') }}"
register: r_packages_install
failed_when: false
when: use_proxy
- name: Install R packages (renv and ggplot2) without proxy
ansible.builtin.shell: |
R -e 'install.packages(c("renv", "ggplot2"), lib="{{ root_path }}/R/library", repos="https://cloud.r-project.org/")'
become: no
environment:
HOME: "{{ root_path }}"
R_LIBS_USER: "{{ root_path }}/R/library"
register: r_packages_install
failed_when: false
when: not use_proxy
- name: Display R package installation output
ansible.builtin.debug:
var: r_packages_install.stdout_lines
when: r_packages_install.stdout_lines is defined
- name: Verify R packages installation
ansible.builtin.shell: |
R -e 'library(renv); library(ggplot2); cat("✓ Packages loaded successfully\n")'
become: no
environment:
HOME: "{{ root_path }}"
R_LIBS_USER: "{{ root_path }}/R/library"
register: r_verify
failed_when: false
- name: Display verification result
ansible.builtin.debug:
msg: "{{ r_verify.stdout if r_verify.rc == 0 else 'Package installation may have failed - check logs' }}"
- name: Display installation summary
ansible.builtin.debug:
msg: |
✓ R installation complete
✓ R packages: renv, ggplot2
To use:
- R command line: type 'R' in terminal
R library location: {{ root_path }}/R/library
R configuration: {{ root_path }}/.Rprofile