2022-08-01 00:42:23 -05:00
|
|
|
---
|
2022-08-01 02:12:33 -05:00
|
|
|
- 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') }}"
|
|
|
|
|
2022-08-01 00:42:23 -05:00
|
|
|
- name: Check if Cargo is installed
|
2022-08-01 01:48:49 -05:00
|
|
|
ansible.builtin.command: which cargo
|
2022-08-01 00:42:23 -05:00
|
|
|
register: cargo_installed
|
2022-08-01 01:48:49 -05:00
|
|
|
failed_when: cargo_installed.rc > 1
|
2022-08-01 00:42:23 -05:00
|
|
|
changed_when: false
|
2022-08-01 02:12:33 -05:00
|
|
|
environment:
|
2022-08-01 21:45:12 -05:00
|
|
|
PATH: "{{ ansible_env.PATH }}:{{ cargo_home }}/bin"
|
2022-08-01 02:12:33 -05:00
|
|
|
CARGO_HOME: "{{ cargo_home }}"
|
|
|
|
RUSTUP_HOME: "{{ rustup_home }}"
|
2022-08-01 00:42:23 -05:00
|
|
|
|
2022-08-01 04:46:13 -05:00
|
|
|
- name: Create temporary working path
|
|
|
|
ansible.builtin.tempfile:
|
|
|
|
state: directory
|
|
|
|
register: rust_working_dir
|
2022-08-01 04:48:42 -05:00
|
|
|
failed_when: rust_working_dir.path is not defined
|
2022-08-01 04:46:13 -05:00
|
|
|
when: cargo_installed.rc != 0
|
|
|
|
|
2022-08-01 00:42:23 -05:00
|
|
|
- name: Download Rust installer
|
2022-08-01 01:52:41 -05:00
|
|
|
when: cargo_installed.rc != 0
|
2022-08-01 00:42:23 -05:00
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: http://sh.rustup.rs
|
2022-08-01 04:52:00 -05:00
|
|
|
dest: "{{ rust_working_dir.path }}/sh.rustup.rs"
|
2022-08-01 00:42:23 -05:00
|
|
|
mode: 0755
|
|
|
|
force: true
|
|
|
|
tags:
|
|
|
|
- rust
|
|
|
|
- prereq
|
|
|
|
|
2022-08-02 16:50:42 -05:00
|
|
|
- name: Ensure Rust & Cargo target dirs are clean
|
|
|
|
ansible.builtin.file:
|
2022-08-03 01:09:37 -05:00
|
|
|
path: "{{ rust_target_dir }}"
|
2022-08-02 16:50:42 -05:00
|
|
|
state: absent
|
|
|
|
force: true
|
|
|
|
when: cargo_installed.rc != 0
|
|
|
|
loop:
|
|
|
|
- "{{ cargo_home }}"
|
|
|
|
- "{{ rustup_home }}"
|
2022-08-03 01:09:37 -05:00
|
|
|
loop_control:
|
|
|
|
loop_var: rust_target_dir
|
2022-08-02 16:50:42 -05:00
|
|
|
|
2022-08-01 00:42:23 -05:00
|
|
|
- name: Install Rust & Cargo
|
2022-08-01 01:52:41 -05:00
|
|
|
when: cargo_installed.rc != 0
|
2022-08-01 00:42:23 -05:00
|
|
|
environment:
|
2022-08-01 02:02:21 -05:00
|
|
|
CARGO_HOME: "{{ cargo_home }}"
|
|
|
|
RUSTUP_HOME: "{{ rustup_home }}"
|
2022-08-01 00:42:23 -05:00
|
|
|
ansible.builtin.command:
|
|
|
|
argv:
|
2022-08-01 04:52:00 -05:00
|
|
|
- "{{ rust_working_dir.path }}/sh.rustup.rs"
|
2022-08-01 00:42:23 -05:00
|
|
|
- -y
|
2022-08-02 23:12:29 -05:00
|
|
|
- --default-toolchain
|
2022-08-02 16:50:42 -05:00
|
|
|
- "{{ rustup_toolchain | default('stable') }}"
|
2022-08-01 00:42:23 -05:00
|
|
|
changed_when: true
|
|
|
|
tags:
|
|
|
|
- rust
|
|
|
|
- prereq
|
2022-08-01 02:02:21 -05:00
|
|
|
|
2022-08-01 21:45:12 -05:00
|
|
|
- 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
|
|
|
|
|
2022-08-01 02:02:21 -05:00
|
|
|
- name: Set Rustup's toolchain
|
|
|
|
ansible.builtin.command:
|
|
|
|
argv:
|
2022-08-01 21:45:12 -05:00
|
|
|
- "rustup"
|
2022-08-01 02:02:21 -05:00
|
|
|
- default
|
|
|
|
- "{{ rustup_toolchain | default('stable') }}"
|
|
|
|
environment:
|
2022-08-01 21:45:12 -05:00
|
|
|
PATH: "{{ ansible_env.PATH }}:{{ cargo_home }}/bin"
|
2022-08-01 02:02:21 -05:00
|
|
|
CARGO_HOME: "{{ cargo_home }}"
|
|
|
|
RUSTUP_HOME: "{{ rustup_home }}"
|
|
|
|
changed_when: true
|
2022-08-01 23:41:47 -05:00
|
|
|
when: "'no toolchains found' in rust_toolchain_installed.stdout"
|