diff --git a/defaults/main.yml b/defaults/main.yml index 7f87e8c..0e695db 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,19 @@ +nvidia_driver_package_state: present nvidia_driver_package_version: '' nvidia_driver_persistence_mode_on: yes nvidia_driver_skip_reboot: no -epel_baseurl: "https://download.fedoraproject.org/pub/epel/$releasever/$basearch/" -epel_gpgkey: "https://epel.mirror.constant.com//RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}" -rhel_cuda_baseurl: "https://developer.download.nvidia.com/compute/cuda/repos/{{ rhel_repo_dir }}/" -rhel_cuda_gpgkey: "https://developer.download.nvidia.com/compute/cuda/repos/{{ rhel_repo_dir }}/7fa2af80.pub" -ubuntu_cuda_gpgkey: "https://developer.download.nvidia.com/compute/cuda/repos/{{ ubuntu_repo_dir }}/7fa2af80.pub" -ubuntu_cuda_apt_key: "7fa2af80" -ubuntu_cuda_baseurl: "http://developer.download.nvidia.com/compute/cuda/repos/{{ ubuntu_repo_dir }}" + +# +# Settings for airgapped systems +# + +# RedHat family +nvidia_driver_rhel_epel_repo_baseurl: "https://download.fedoraproject.org/pub/epel/$releasever/$basearch/" +nvidia_driver_rhel_epel_repo_gpgkey: "https://epel.mirror.constant.com//RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}" +nvidia_driver_rhel_cuda_repo_baseurl: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _rhel_repo_dir }}/" +nvidia_driver_rhel_cuda_repo_gpgkey: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _rhel_repo_dir }}/7fa2af80.pub" + +# Ubuntu +nvidia_driver_ubuntu_cuda_repo_gpgkey_url: "https://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}/7fa2af80.pub" +nvidia_driver_ubuntu_cuda_repo_gpgkey_id: "7fa2af80" +nvidia_driver_ubuntu_cuda_repo_baseurl: "http://developer.download.nvidia.com/compute/cuda/repos/{{ _ubuntu_repo_dir }}" diff --git a/tasks/redhat-post-install.yml b/tasks/install-redhat.yml similarity index 55% rename from tasks/redhat-post-install.yml rename to tasks/install-redhat.yml index 65fe713..4f8e424 100644 --- a/tasks/redhat-post-install.yml +++ b/tasks/install-redhat.yml @@ -1,4 +1,30 @@ --- +- name: add epel repo + yum_repository: + name: epel + description: EPEL YUM repo + baseurl: "{{ nvidia_driver_rhel_epel_repo_baseurl }}" + gpgkey: "{{ nvidia_driver_rhel_epel_repo_gpgkey }}" + +- name: install dependencies + yum: + name: dkms + state: latest + +- name: add repo + yum_repository: + name: cuda + description: NVIDIA CUDA YUM Repo + baseurl: "{{ nvidia_driver_rhel_cuda_repo_baseurl }}" + gpgkey: "{{ nvidia_driver_rhel_cuda_repo_gpgkey }}" + +- name: install driver packages + yum: + name: "{{ nvidia_driver_package_version | ternary('cuda-drivers='+nvidia_driver_package_version, 'cuda-drivers') }}" + state: "{{ nvidia_driver_package_state }}" + autoremove: "{{ nvidia_driver_package_state == 'absent' }}" + register: install_driver + # The driver package pulls in the latest kernel-headers package, but not the # latest kernel. Check to see if there is a mismatch. diff --git a/tasks/install-ubuntu.yml b/tasks/install-ubuntu.yml new file mode 100644 index 0000000..66dec37 --- /dev/null +++ b/tasks/install-ubuntu.yml @@ -0,0 +1,23 @@ +--- +- name: remove ppa + apt_repository: + repo: ppa:graphics-drivers/ppa + state: absent + +- name: add key + apt_key: + url: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_url }}" + id: "{{ nvidia_driver_ubuntu_cuda_repo_gpgkey_id }}" + +- name: add repo + apt_repository: + repo: "deb {{ nvidia_driver_ubuntu_cuda_repo_baseurl }} /" + update_cache: yes + +- name: install driver packages + apt: + name: "{{ nvidia_driver_package_version | ternary('cuda-drivers='+nvidia_driver_package_version, 'cuda-drivers') }}" + state: "{{ nvidia_driver_package_state }}" + autoremove: "{{ nvidia_driver_package_state == 'absent' }}" + purge: "{{ nvidia_driver_package_state == 'absent' }}" + register: install_driver diff --git a/tasks/main.yml b/tasks/main.yml index 0cf06a8..cc7da24 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,22 +5,12 @@ state: absent ignore_errors: true -- name: ubuntu pre-install tasks - include_tasks: ubuntu-pre-install.yml +- name: ubuntu install tasks + include_tasks: install-ubuntu.yml when: ansible_distribution == 'Ubuntu' -- name: redhat family pre-install tasks - include_tasks: redhat-pre-install.yml - when: ansible_os_family == 'RedHat' - -- name: install driver packages - package: - name: "{{ nvidia_driver_package_version | ternary('cuda-drivers='+nvidia_driver_package_version, 'cuda-drivers') }}" - state: present - register: install_driver - -- name: redhat family post-install tasks - include_tasks: redhat-post-install.yml +- name: redhat family install tasks + include_tasks: install-redhat.yml when: ansible_os_family == 'RedHat' - name: create persistenced override dir @@ -45,6 +35,7 @@ systemd: name: nvidia-persistenced enabled: yes + when: nvidia_driver_package_state != 'absent' - name: reboot after driver install reboot: diff --git a/tasks/redhat-pre-install.yml b/tasks/redhat-pre-install.yml deleted file mode 100644 index dd2e0b1..0000000 --- a/tasks/redhat-pre-install.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: add epel repo - yum_repository: - name: epel - description: EPEL YUM repo - baseurl: "{{ epel_baseurl }}" - gpgkey: "{{ epel_gpgkey }}" - -- name: install dependencies - yum: - name: dkms - state: latest - -- name: add repo - yum_repository: - name: cuda - description: NVIDIA CUDA YUM Repo - gpgkey: "{{ rhel_cuda_gpgkey }}" - baseurl: "{{ rhel_cuda_baseurl }}" diff --git a/tasks/ubuntu-pre-install.yml b/tasks/ubuntu-pre-install.yml deleted file mode 100644 index 4907bb5..0000000 --- a/tasks/ubuntu-pre-install.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: remove ppa - apt_repository: - repo: ppa:graphics-drivers/ppa - state: absent - -- name: add key - apt_key: - url: "{{ ubuntu_cuda_gpgkey }}" - id: "{{ ubuntu_cuda_apt_key }}" - -- name: add repo - apt_repository: - repo: "deb {{ ubuntu_cuda_baseurl }} /" - update_cache: yes diff --git a/vars/main.yml b/vars/main.yml index 6a48d95..c994f5b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ -ubuntu_repo_dir: "{{ ansible_distribution | lower }}{{ ansible_distribution_version | replace('.', '') }}/{{ ansible_architecture }}" -rhel_repo_dir: "rhel{{ ansible_distribution_major_version }}/{{ ansible_architecture }}" +_ubuntu_repo_dir: "{{ ansible_distribution | lower }}{{ ansible_distribution_version | replace('.', '') }}/{{ ansible_architecture }}" +_rhel_repo_dir: "rhel{{ ansible_distribution_major_version }}/{{ ansible_architecture }}"