Ubuntu20.04安装nVidia驱动ansible剧本
Ubuntu20.04安装nVidia驱动ansible剧本
---
- name: 获取nVidia显卡驱动状态
shell: sudo lspci |grep -i NVIDIA|grep 'VGA'|wc -l
register: NVIDIA_STATE
- name: 打印获取到的nVidia显卡驱动状态
debug: msg={{ NVIDIA_STATE['stdout'] }}
- block:
- name: 将nVidia驱动复制到节点
copy: src="/data/bin/drive/NVIDIA-Linux-x86_64-460.91.03.run" dest=/tmp/NVIDIA-Linux-x86_64-460.91.03.run mode=0755
- name: 删除开源nVidia驱动nouveau
modprobe: name=nouveau state=absent
ignore_errors: True
- name: 添加nouveau到黑名单文件/etc/modprobe.d/blacklist.conf
blockinfile:
path: /etc/modprobe.d/blacklist.conf
block: |
blacklist nouveau
options nouveau modeset=0
marker: "# {mark} ANSIBLE MANAGED BLOCK "
- name: 运行 update-initramfs -u 更新驱动到intramfs.img中
shell: update-initramfs -u
- name: 安装显卡驱动文件 NVIDIA-Linux-x86_64-460.91.03.run
shell:
cmd: /tmp/NVIDIA-Linux-x86_64-460.91.03.run --accept-license --silent --no-nouveau-check --disable-nouveau --no-opengl-files && touch /tmp/install-nvidia-ok || touch /tmp/install-nvidia-err
creates: /tmp/install-nvidia-ok
- name: 保持内核不更新,Hold linux-image-generic linux-headers-generic not update
shell:
cmd: apt-mark hold linux-image-generic linux-headers-generic && touch /tmp/hold-apt-ok || touch /tmp/hold-apt-err
creates: /tmp/hold-apt-ok
when: NVIDIA_STATE['stdout'] != "0"