Dot_Files/tasks/install-rust.yml

70 lines
1.9 KiB
YAML
Raw Normal View History

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
- 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
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
- 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
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 21:45:12 -05:00
when: rust_toolchain_installed.stdout == 'no toolchains found'