- name: Check if Rust is installed
  ansible.builtin.shell: source $HOME/.cargo/env && rustc --version
  register: rust_check
  changed_when: false
  failed_when: false
  args:
    executable: /bin/bash

- name: Download Rust installation script
  ansible.builtin.get_url:
    url: https://sh.rustup.rs
    dest: /tmp/rustup.sh
    mode: '0755'
  when: rust_check.rc != 0

- name: Install Rust and Cargo
  ansible.builtin.shell: |
    set -o pipefail
    /tmp/rustup.sh -y
  args:
    creates: ~/.cargo/bin/rustc
  when: rust_check.rc != 0
