我想为一组服务器配置 IOMMU 设置。执行此操作需要在 Intel 服务器上对 grub 配置进行如下更改:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on iommu=pt"
与 AMD 服务器类似:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on iommu=pt"
我尝试了以下方法:
---
- name: Configure GRUB for IOMMU based on CPU manufacturer
hosts: your_target_hosts
become: yes # Necessary for permissions to edit GRUB config and update GRUB
tasks:
- name: Set GRUB options for Intel systems
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX_DEFAULT='
line: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on iommu=pt"'
backrefs: yes
when: ansible_processor_vendor == 'GenuineIntel'
notify: update-grub
- name: Set GRUB options for AMD systems
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX_DEFAULT='
line: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on iommu=pt"'
backrefs: yes
when: ansible_processor_vendor == 'AuthenticAMD'
notify: update-grub
handlers:
- name: update-grub
ansible.builtin.command:
cmd: update-grub
但是,当我运行剧本时,Ansible 说ansible_processor_vendor
未定义。
我该如何实际构建这个剧本来适当地完成对每个供应商的配置更改?
答案1
这似乎有效!我不得不使用when: ansible_processor[1] == 'GenuineIntel'
:
---
- name: Configure GRUB for IOMMU based on CPU manufacturer
hosts: your_target_hosts
become: yes # Necessary for permissions to edit GRUB config and update GRUB
tasks:
- name: Set GRUB options for Intel systems
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX_DEFAULT='
line: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on iommu=pt"'
backrefs: yes
when: ansible_processor[1] == 'GenuineIntel'
notify: update-grub
- name: Set GRUB options for AMD systems
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX_DEFAULT='
line: 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on iommu=pt"'
backrefs: yes
when: ansible_processor[1] == 'AuthenticAMD'
notify: update-grub
handlers:
- name: update-grub
ansible.builtin.command:
cmd: update-grub