diff --git a/defaults/main.yml b/defaults/main.yml index 2877b5d..5c8bcf4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ cuda_install_packages: [] -cuda_install_nvarch: "{{ lookup('ansible.builtin.env', 'NVARCH', default='x86_64') }}" -cuda_install_distro: "{{ cuda_install_distribution_map[cuda_install_distribution_tag] }}" +cuda_install_nvarch: "{{ lookup('ansible.builtin.env', 'CUDA_ARCH', default='x86_64') }}" +cuda_install_distro: "{{ lookup('ansible.builtin.env', 'CUDA_DISTRO') }}" cuda_install_nvidia_cuda_repos: https://developer.download.nvidia.com/compute/cuda/repos cuda_install_debian_family_keyring_filename: cuda-keyring_1.1-1_all.deb diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 9a6208f..dfcee1f 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,8 +1,9 @@ --- - name: Verify hosts: all + gather_facts: false tasks: - - name: Verify CUDA Toolkit + - name: Verify CUDA installation ansible.builtin.command: cmd: "/usr/local/cuda-12.4/bin/nvcc --version" changed_when: false diff --git a/tasks/debian_family_install.yml b/tasks/debian-family.yml similarity index 65% rename from tasks/debian_family_install.yml rename to tasks/debian-family.yml index 9b75a65..9c88c5f 100644 --- a/tasks/debian_family_install.yml +++ b/tasks/debian-family.yml @@ -1,9 +1,9 @@ -- name: debian_family_install | Install cuda-keyring +- name: debian-family | Install CUDA keyring become: true ansible.builtin.apt: deb: "{{ cuda_install_debian_family_keyring_file_url }}" -- name: debian_family_install | Install CUDA packages via apt +- name: debian-family | Install CUDA packages via apt become: true ansible.builtin.apt: name: "{{ cuda_install_packages }}" diff --git a/tasks/main.yml b/tasks/main.yml index 76ab630..7296ba6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,28 @@ --- -- name: Dispatch to distro family specific tasks +- name: Include distribution specific variables + ansible.builtin.include_vars: + file: "{{ lookup('ansible.builtin.first_found', search_hierarchy) }}" + vars: + search_hierarchy: + files: + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}-{{ ansible_distribution_version }}.yml" + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}.yml" + - "{{ ansible_os_family | lower | replace('_', '-') | replace(' ', '-') }}-family.yml" + - "default_distro.yml" + paths: + - 'vars' + +- name: Perform distribution specific tasks ansible.builtin.include_tasks: - file: "{{ ansible_os_family | lower | replace('_', '-') | replace(' ', '-') }}_family_install.yml" + file: "{{ lookup('ansible.builtin.first_found', search_hierarchy) }}" + vars: + search_hierarchy: + files: + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}-{{ ansible_distribution_version }}.yml" + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') }}.yml" + - "{{ ansible_os_family | lower | replace('_', '-') | replace(' ', '-') }}-family.yml" + - "default_distro.yml" + paths: + - 'tasks' diff --git a/tasks/redhat_family_install.yml b/tasks/redhat-family.yml similarity index 67% rename from tasks/redhat_family_install.yml rename to tasks/redhat-family.yml index 1cf8ee3..a3ad335 100644 --- a/tasks/redhat_family_install.yml +++ b/tasks/redhat-family.yml @@ -1,10 +1,10 @@ -- name: redhat_family_install | Download the CUDA repository file +- name: redhat-family | Download the CUDA repository file ansible.builtin.get_url: url: "{{ cuda_install_redhat_family_repo_baseurl }}" dest: /etc/yum.repos.d/nvidia_cuda.repo mode: '0644' -- name: redhat_family_install | Install CUDA packages via yum +- name: redhat-family | Install CUDA packages via yum become: true ansible.builtin.yum: name: "{{ cuda_install_packages }}" diff --git a/vars/debian-10.yml b/vars/debian-10.yml new file mode 100644 index 0000000..83cca44 --- /dev/null +++ b/vars/debian-10.yml @@ -0,0 +1 @@ +cuda_install_distro: debian10 diff --git a/vars/debian-11.yml b/vars/debian-11.yml new file mode 100644 index 0000000..9419e50 --- /dev/null +++ b/vars/debian-11.yml @@ -0,0 +1 @@ +cuda_install_distro: debian11 diff --git a/vars/debian-12.yml b/vars/debian-12.yml new file mode 100644 index 0000000..172b5f6 --- /dev/null +++ b/vars/debian-12.yml @@ -0,0 +1 @@ +cuda_install_distro: debian12 diff --git a/vars/fedora-39.yml b/vars/fedora-39.yml new file mode 100644 index 0000000..2fd725f --- /dev/null +++ b/vars/fedora-39.yml @@ -0,0 +1 @@ +cuda_install_distro: fedora39 diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index 51597cc..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,19 +0,0 @@ -cuda_install_distribution_tag: >- - {{ ansible_distribution | lower | replace('_', '-') | replace(' ', '-') ~ ansible_distribution_major_version }} - -cuda_install_distribution_map: - centos8: rhel8 - debian11: debian11 - debian12: debian12 - fedora37: fedora37 - fedora38: fedora37 - fedora39: fedora39 - redhat8: rhel8 - redhat9: rhel9 - rocky8: rhel8 - rocky9: rhel9 - ubuntu20: ubuntu2004 - ubuntu21: ubuntu2004 - ubuntu22: ubuntu2204 - ubuntu23: ubuntu2204 - ubuntu24: ubuntu2404 diff --git a/vars/redhat-8.yml b/vars/redhat-8.yml new file mode 100644 index 0000000..c89382b --- /dev/null +++ b/vars/redhat-8.yml @@ -0,0 +1 @@ +cuda_install_distro: rhel8 diff --git a/vars/redhat-9.yml b/vars/redhat-9.yml new file mode 100644 index 0000000..8b2ca38 --- /dev/null +++ b/vars/redhat-9.yml @@ -0,0 +1 @@ +cuda_install_distro: rhel9 diff --git a/vars/rocky-8.yml b/vars/rocky-8.yml new file mode 100644 index 0000000..c89382b --- /dev/null +++ b/vars/rocky-8.yml @@ -0,0 +1 @@ +cuda_install_distro: rhel8 diff --git a/vars/rocky-9.yml b/vars/rocky-9.yml new file mode 100644 index 0000000..8b2ca38 --- /dev/null +++ b/vars/rocky-9.yml @@ -0,0 +1 @@ +cuda_install_distro: rhel9 diff --git a/vars/ubuntu-20.04.yml b/vars/ubuntu-20.04.yml new file mode 100644 index 0000000..f52da90 --- /dev/null +++ b/vars/ubuntu-20.04.yml @@ -0,0 +1 @@ +cuda_install_distro: ubuntu2004 diff --git a/vars/ubuntu-22.04.yml b/vars/ubuntu-22.04.yml new file mode 100644 index 0000000..721d442 --- /dev/null +++ b/vars/ubuntu-22.04.yml @@ -0,0 +1 @@ +cuda_install_distro: ubuntu2204 diff --git a/vars/ubuntu-24.04.yml b/vars/ubuntu-24.04.yml new file mode 100644 index 0000000..52feb67 --- /dev/null +++ b/vars/ubuntu-24.04.yml @@ -0,0 +1 @@ +cuda_install_distro: ubuntu2404