Nous avons déjà installé Julia sur notre machine de déploiement mais pas encore dans nos conteneurs de travail.
Le playbook Ansible install-julia.yml
ci-dessous permet l’installation de Julia dans les conteneurs de travail.
---
- name: Installer Julia
hosts: calcul_distribue
become: yes
vars:
julia_version: "latest" # Utilisez "latest" pour la dernière version ou spécifiez une version comme "1.11.1"
tasks:
- name: Télécharger le script d'installation de JuliaUp
get_url:
url: https://install.julialang.org
dest: /tmp/julia-installer.sh
mode: '0755'
- name: Installer JuliaUp
shell: /tmp/julia-installer.sh -y
args:
creates: "{{ ansible_env.HOME }}/.juliaup/bin/juliaup"
- name: Vérifier l'existence du fichier .bashrc
stat:
path: "{{ ansible_env.HOME }}/.bashrc"
register: bashrc_file
- name: Créer le fichier .bashrc s'il n'existe pas
file:
path: "{{ ansible_env.HOME }}/.bashrc"
state: touch
mode: '0644'
when: not bashrc_file.stat.exists
- name: Ajouter Julia au PATH dans .bashrc
lineinfile:
path: "{{ ansible_env.HOME }}/.bashrc"
line: 'export PATH="{{ ansible_env.HOME }}/.juliaup/bin:$PATH"'
state: present
- name: Installer la version spécifiée de Julia
shell: |
export PATH="{{ ansible_env.HOME }}/.juliaup/bin:$PATH"
juliaup add {{ julia_version }}
args:
executable: /bin/bash
when: julia_version != "latest"
- name: Définir la version par défaut de Julia
shell: |
export PATH="{{ ansible_env.HOME }}/.juliaup/bin:$PATH"
juliaup default {{ julia_version }}
args:
executable: /bin/bash
when: julia_version != "latest"
- name: Mettre à jour Julia vers la dernière version stable
shell: |
export PATH="{{ ansible_env.HOME }}/.juliaup/bin:$PATH"
juliaup update
args:
executable: /bin/bash
when: julia_version == "latest"
- name: Nettoyer le script d'installation
file:
path: /tmp/julia-installer.sh
state: absent
- name: Vérifier l'installation de Julia
shell: |
export PATH="{{ ansible_env.HOME }}/.juliaup/bin:$PATH"
julia --version
register: julia_version_output
changed_when: false
- name: Afficher la version de Julia installée
debug:
var: julia_version_output.stdout_lines
Exécutons ce playbook Ansible en tant qu’utilisateur worker
sur nos conteneurs du groupe calcul_distribue
(conteneurs ubuntu-lxc-n
avec n
entier de 1 à 5)
deployer@ubuntu-deploy:~/homelab_julia_pve_tf_ansible$ ANSIBLE_REMOTE_USER=worker ansible-playbook -i dynamic-inventory.proxmox.yml install-julia.yml
PLAY [Installer Julia] ***************************************************************************************
TASK [Gathering Facts] ***************************************************************************************
ok: [ubuntu-lxc-4]
ok: [ubuntu-lxc-1]
ok: [ubuntu-lxc-5]
ok: [ubuntu-lxc-2]
ok: [ubuntu-lxc-3]
TASK [Télécharger le script d'installation de JuliaUp] *******************************************************
changed: [ubuntu-lxc-1]
changed: [ubuntu-lxc-2]
changed: [ubuntu-lxc-3]
changed: [ubuntu-lxc-4]
changed: [ubuntu-lxc-5]
TASK [Installer JuliaUp] *************************************************************************************
changed: [ubuntu-lxc-2]
changed: [ubuntu-lxc-1]
changed: [ubuntu-lxc-3]
changed: [ubuntu-lxc-5]
changed: [ubuntu-lxc-4]
TASK [Vérifier l'existence du fichier .bashrc] ***************************************************************
ok: [ubuntu-lxc-4]
ok: [ubuntu-lxc-1]
ok: [ubuntu-lxc-2]
ok: [ubuntu-lxc-5]
ok: [ubuntu-lxc-3]
TASK [Créer le fichier .bashrc s'il n'existe pas] ************************************************************
skipping: [ubuntu-lxc-5]
skipping: [ubuntu-lxc-2]
skipping: [ubuntu-lxc-4]
skipping: [ubuntu-lxc-1]
skipping: [ubuntu-lxc-3]
TASK [Ajouter Julia au PATH dans .bashrc] ********************************************************************
changed: [ubuntu-lxc-1]
changed: [ubuntu-lxc-4]
changed: [ubuntu-lxc-2]
changed: [ubuntu-lxc-5]
changed: [ubuntu-lxc-3]
TASK [Installer la version spécifiée de Julia] ***************************************************************
skipping: [ubuntu-lxc-5]
skipping: [ubuntu-lxc-2]
skipping: [ubuntu-lxc-4]
skipping: [ubuntu-lxc-1]
skipping: [ubuntu-lxc-3]
TASK [Définir la version par défaut de Julia] ****************************************************************
skipping: [ubuntu-lxc-5]
skipping: [ubuntu-lxc-2]
skipping: [ubuntu-lxc-4]
skipping: [ubuntu-lxc-1]
skipping: [ubuntu-lxc-3]
TASK [Mettre à jour Julia vers la dernière version stable] ***************************************************
changed: [ubuntu-lxc-5]
changed: [ubuntu-lxc-4]
changed: [ubuntu-lxc-2]
changed: [ubuntu-lxc-1]
changed: [ubuntu-lxc-3]
TASK [Nettoyer le script d'installation] *********************************************************************
changed: [ubuntu-lxc-4]
changed: [ubuntu-lxc-1]
changed: [ubuntu-lxc-5]
changed: [ubuntu-lxc-2]
changed: [ubuntu-lxc-3]
TASK [Vérifier l'installation de Julia] **********************************************************************
ok: [ubuntu-lxc-5]
ok: [ubuntu-lxc-4]
ok: [ubuntu-lxc-1]
ok: [ubuntu-lxc-2]
ok: [ubuntu-lxc-3]
TASK [Afficher la version de Julia installée] ****************************************************************
ok: [ubuntu-lxc-5] => {
"julia_version_output.stdout_lines": [
"julia version 1.11.1"
]
}
ok: [ubuntu-lxc-2] => {
"julia_version_output.stdout_lines": [
"julia version 1.11.1"
]
}
ok: [ubuntu-lxc-4] => {
"julia_version_output.stdout_lines": [
"julia version 1.11.1"
]
}
ok: [ubuntu-lxc-1] => {
"julia_version_output.stdout_lines": [
"julia version 1.11.1"
]
}
ok: [ubuntu-lxc-3] => {
"julia_version_output.stdout_lines": [
"julia version 1.11.1"
]
}
PLAY RECAP ***************************************************************************************************
ubuntu-lxc-1 : ok=9 changed=5 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
ubuntu-lxc-2 : ok=9 changed=5 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
ubuntu-lxc-3 : ok=9 changed=5 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
ubuntu-lxc-4 : ok=9 changed=5 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
ubuntu-lxc-5 : ok=9 changed=5 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0