-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJulia.yml
More file actions
211 lines (190 loc) · 6.72 KB
/
Copy pathJulia.yml
File metadata and controls
211 lines (190 loc) · 6.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
---
- name: Install Julia on Ubuntu
hosts: all
vars_files:
- config.yml
remote_user: "{{ username }}"
connection: local
vars:
julia_version: "1.12.4"
julia_major_minor: "1.12"
julia_install_dir: "/opt/julia"
julia_bin_link: "/usr/local/bin/julia"
actual_user: "{{ lookup('env', 'SUDO_USER') | default(username) }}"
julia_packages:
- Plots
- JSON
tasks:
- name: Install required dependencies
apt:
name:
- wget
- tar
- ca-certificates
state: present
update_cache: yes
become: true
- name: Create Julia installation directory
file:
path: "{{ julia_install_dir }}"
state: directory
mode: '0755'
become: true
- name: Download Julia tarball
get_url:
url: "https://julialang-s3.julialang.org/bin/linux/x64/{{ julia_major_minor }}/julia-{{ julia_version }}-linux-x86_64.tar.gz"
dest: "/tmp/julia-{{ julia_version }}.tar.gz"
mode: '0644'
become: true
- name: Extract Julia archive
unarchive:
src: "/tmp/julia-{{ julia_version }}.tar.gz"
dest: "{{ julia_install_dir }}"
remote_src: yes
extra_opts: [--strip-components=1]
creates: "{{ julia_install_dir }}/bin/julia"
become: true
- name: Create symbolic link for Julia
file:
src: "{{ julia_install_dir }}/bin/julia"
dest: "{{ julia_bin_link }}"
state: link
become: true
- name: Verify Julia installation
command: julia --version
register: julia_version_output
changed_when: false
- name: Display Julia version
debug:
var: julia_version_output.stdout
- name: Clean up downloaded tarball
file:
path: "/tmp/julia-{{ julia_version }}.tar.gz"
state: absent
become: true
- name: Download juliaup installer
ansible.builtin.get_url:
url: https://install.julialang.org
dest: /tmp/juliaup-installer.sh
mode: '0755'
become: false
- name: Run juliaup installer as actual user
ansible.builtin.shell:
cmd: bash /tmp/juliaup-installer.sh -y --background-selfupdate 0
args:
creates: "{{ root_path }}/.juliaup/bin/juliaup"
environment:
HOME: "{{ root_path }}"
USER: "{{ actual_user }}"
JULIAUP_BACKGROUND_SELFUPDATE: "0"
become: true
become_user: "{{ actual_user }}"
- name: Add juliaup to PATH in .bashrc with proxy
ansible.builtin.lineinfile:
path: "{{ root_path }}/.bashrc"
line: 'export PATH="$HOME/.juliaup/bin:$PATH"; export HTTP_PROXY="{{ http_proxy }}"; export HTTPS_PROXY="{{ http_proxy }}"'
regexp: '^export PATH=.*\.juliaup/bin'
state: present
create: yes
backup: yes
environment:
HTTP_PROXY: "{{ http_proxy }}"
HTTPS_PROXY: "{{ http_proxy }}"
FTP_PROXY: "{{ ftp_proxy }}"
NO_PROXY: "{{ no_proxy }}"
become: true
become_user: "{{ actual_user }}"
when: use_proxy
- name: Add juliaup to PATH in .bashrc without proxy
ansible.builtin.lineinfile:
path: "{{ root_path }}/.bashrc"
line: 'export PATH="$HOME/.juliaup/bin:$PATH"'
regexp: '^export PATH=.*\.juliaup/bin'
state: present
create: yes
backup: yes
become: true
become_user: "{{ actual_user }}"
when: not use_proxy
- name: Proxy settings
ansible.builtin.debug:
msg:
- "HTTP_PROXY set to {{ lookup('env', 'HTTP_PROXY') }}"
- "HTTPS_PROXY set to {{ lookup('env', 'HTTPS_PROXY') }}"
when: use_proxy
- name: Create a startup.jl file in .julia/config and add the proxy settings
ansible.builtin.shell:
cmd:
mkdir ${HOME}/.julia/config;
touch ${HOME}/.julia/config/startup.jl;
echo ENV[\"JULIA_SSL_NO_VERIFY_HOSTS\"] = \"pkg.julialang.org\" > ${HOME}/.julia/config/startup.jl;
echo ENV[\"JULIA_PKG_SERVER\"]=\"\" >> ${HOME}/.julia/config/startup.jl;
echo ENV[\"HTTP_PROXY\"]=\"{{ http_proxy }}\" >> ${HOME}/.julia/config/startup.jl;
echo ENV[\"HTTPS_PROXY\"]=\"{{ http_proxy }}\" >> ${HOME}/.julia/config/startup.jl
become: true
become_user: "{{ actual_user }}"
when: use_proxy
- name: Create a startup.jl file in .julia/config without the proxy settings
ansible.builtin.shell:
cmd:
mkdir ${HOME}/.julia/config;
touch ${HOME}/.julia/config/startup.jl;
echo ENV[\"JULIA_SSL_NO_VERIFY_HOSTS\"] = \"pkg.julialang.org\" > ${HOME}/.julia/config/startup.jl;
echo ENV[\"JULIA_PKG_SERVER\"]=\"\" >> ${HOME}/.julia/config/startup.jl;
become: true
become_user: "{{ actual_user }}"
when: not use_proxy
- name: Install Julia packages
ansible.builtin.shell:
cmd: |
julia -e 'using Pkg; Pkg.add("{{ item }}")'
loop: "{{ julia_packages }}"
environment:
HOME: "{{ root_path }}"
USER: "{{ actual_user }}"
become: true
become_user: "{{ actual_user }}"
register: pkg_install
changed_when: "'Installed' in pkg_install.stdout or 'Updating' in pkg_install.stdout"
- name: Verify installed Julia packages with proxy
ansible.builtin.shell:
cmd: |
julia -e 'using Pkg; Pkg.status()'
environment:
HOME: "{{ root_path }}"
USER: "{{ actual_user }}"
HTTP_PROXY: "{{ http_proxy }}" # Probably not really needed ...
HTTPS_PROXY: "{{ http_proxy }}"
FTP_PROXY: "{{ ftp_proxy }}"
NO_PROXY: "{{ no_proxy }}"
become: true
become_user: "{{ actual_user }}"
register: pkg_status
changed_when: false
when: use_proxy
- name: Verify installed Julia packages without proxy
ansible.builtin.shell:
cmd: |
julia -e 'using Pkg; Pkg.status()'
environment:
HOME: "{{ root_path }}"
USER: "{{ actual_user }}"
become: true
become_user: "{{ actual_user }}"
register: pkg_status
changed_when: false
when: not use_proxy
- name: Display installed packages
ansible.builtin.debug:
msg: "{{ (pkg_status | default({})).get('stdout_lines', ((pkg_status | default({})).get('stdout', '')).split('\\n')) }}"
- name: Clean up installer
ansible.builtin.file:
path: /tmp/juliaup-installer.sh
state: absent
become: false
- name: Display success message
ansible.builtin.debug:
msg:
- "juliaup and Julia packages have been installed!"
- "Installed packages: {{ julia_packages | join(', ') }}"
- "Run 'source ~/.bashrc' or open a new terminal to use juliaup."