- name: Installer rust et cargo
  apt:
    state: present
    name:
     - rustc
     - cargo
     - cargo-doc
    update_cache: yes

- name: Créer unE user rust pour compiler les crates
  user:
    name: "rust"
    state: present
    skeleton: /etc/skel
    shell: /bin/bash
    system: no
    createhome: yes
    home: "/home/rust"

- name: Créer le dossier pour cargo
  file:
    path: /home/rust/.cargo
    state: directory
    owner: rust
    group: rust

- name: Transférer les permissions de /usr/local/bin à rust
  file:
    path: /usr/local/bin
    state: directory
    owner: rust
    group: rust
    mode: 0755
    recurse: yes

- name: Créer un symlink de ~rust/.cargo/bin vers /usr/local/bin
  file:
    dest: /home/rust/.cargo/bin
    src: /usr/local/bin
    force: yes
    follow: no
    state: link

- name: Installer les paquets rust qui nous intéresse
  become:
  become_user: rust
  command:
    cmd: "cargo install {{ item }}"
    creates: "/usr/local/bin/{{ item }}"
  loop: "{{ packages.rust }}"
