--- - name: Set environment variables if not set ansible.builtin.set_fact: cargo_home: "{{ cargo_home | default(xdg_data_home + '/cargo') }}" rustup_home: "{{ rustup_home | default(xdg_data_home + '/rustup') }}" - name: Check if Cargo is installed ansible.builtin.command: which cargo register: cargo_installed failed_when: cargo_installed.rc > 1 changed_when: false environment: CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" - name: Download Rust installer when: cargo_installed.rc != 0 ansible.builtin.get_url: url: http://sh.rustup.rs dest: /tmp/sh.rustup.rs mode: 0755 force: true tags: - rust - prereq - name: Install Rust & Cargo when: cargo_installed.rc != 0 environment: CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" ansible.builtin.command: argv: - /tmp/sh.rustup.rs - -y changed_when: true tags: - rust - prereq - name: Set Rustup's toolchain ansible.builtin.command: argv: - "{{ cargo_home }}/bin/rustup" - default - "{{ rustup_toolchain | default('stable') }}" environment: CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" changed_when: true when: cargo_installed.rc != 0