--- - 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: PATH: "{{ ansible_env.PATH }}:{{ cargo_home }}/bin" CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" - name: Create temporary working path ansible.builtin.tempfile: state: directory register: rust_working_dir failed_when: rust_working_dir.path is not defined when: cargo_installed.rc != 0 - name: Download Rust installer when: cargo_installed.rc != 0 ansible.builtin.get_url: url: http://sh.rustup.rs dest: "{{ rust_working_dir.path }}/sh.rustup.rs" mode: 0755 force: true tags: - rust - prereq - name: Ensure Rust & Cargo target dirs are clean ansible.builtin.file: path: "{{ item }}" state: absent force: true when: cargo_installed.rc != 0 loop: - "{{ cargo_home }}" - "{{ rustup_home }}" - name: Install Rust & Cargo when: cargo_installed.rc != 0 environment: CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" ansible.builtin.command: argv: - "{{ rust_working_dir.path }}/sh.rustup.rs" - -y - --default-toolchain - "{{ rustup_toolchain | default('stable') }}" changed_when: true tags: - rust - prereq - name: Check if a Rust toolchain is set ansible.builtin.command: rustup toolchain list environment: PATH: "{{ ansible_env.PATH }}:{{ cargo_home }}/bin" CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" register: rust_toolchain_installed changed_when: false - name: Set Rustup's toolchain ansible.builtin.command: argv: - "rustup" - default - "{{ rustup_toolchain | default('stable') }}" environment: PATH: "{{ ansible_env.PATH }}:{{ cargo_home }}/bin" CARGO_HOME: "{{ cargo_home }}" RUSTUP_HOME: "{{ rustup_home }}" changed_when: true when: "'no toolchains found' in rust_toolchain_installed.stdout" - name: Install common Rust build dependencies for Debian based systems become: true ansible.builtin.apt: name: build-essential state: present when: ansible_facts.os_family == 'Debian' - name: Install common Rust build dependencies for RedHat based systems become: true ansible.builtin.dnf: name: - cmake - automake - gcc state: present when: ansible_facts.os_family == 'RedHat' - name: Install common Rust build dependencies for Arch community.general.pacman: name: - cmake - gcc - automake state: present when: ansible_facts.distribution == 'Archlinux' - name: Install common Rust build dependencies for MacOS community.general.homebrew: name: - make - gcc - llvm state: present when: ansible_facts.distribution == 'MacOSX'