1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 - name: Set iommu_boot_params for Intel
17 iommu_boot_params: ' intel_iommu=on iommu=pt'
18 when: hostvars[inventory_hostname]['ansible_system_vendor'] == "Intel Corporation"
20 - name: Set iommu_boot_params for AMD
22 iommu_boot_params: ' amd_iommu=on iommu=pt'
23 when: hostvars[inventory_hostname]['ansible_system_vendor'] == "AuthenticAMD"
25 - name: Set facts for this role
27 hugepages_help_string: ' # added by hugepages role'
28 iommu_help_string: ', added by iommu role'
29 hugepages_params: " default_hugepagesz=1G hugepagesz=1G hugepages=8"
30 iommu_original_kernel_params: 'GRUB_CMDLINE_LINUX="\$GRUB_CMDLINE_LINUX{{ hugepages_params }}'
31 iommu_enabled_kernel_params: '{{ iommu_original_kernel_params }}{{ iommu_boot_params }}"'
32 iommu_enabled_kernel_params_with_help: '{{ iommu_original_kernel_params }}{{ iommu_boot_params }}"{{ hugepages_help_string }}{{ iommu_help_string }}'
34 - name: check if iommu is set by this role in /etc/default/grub
36 path: /etc/default/grub
37 line: '{{ iommu_enabled_kernel_params_with_help }}'
40 register: is_mine_iommu_etc_grub
43 - name: check if iommu is set by someone else
44 command: "grep -o 'iommu' /etc/default/grub"
49 msg: "Iommu already set by someone else"
50 when: is_mine_iommu_etc_grub.changed == false and is_iommu.stdout != ""
52 - name: 'Configure iommu in /etc/default/grub'
53 # and /boot/grub/grub.cfg(when: ansible_distribution == "Ubuntu")'
55 path: /etc/default/grub
56 regexp: '({{ iommu_original_kernel_params }})"{{ hugepages_help_string }}'
57 line: '\1{{ iommu_boot_params }}"{{ hugepages_help_string }}{{ iommu_help_string }}'
59 when: is_mine_iommu_etc_grub.changed == true
61 - name: find boot grub.cfg
69 - include: manual_modify_grub.yml
70 # only tested on Ubuntu, kernel line is probably different on other distros
71 with_items: "{{ grub_files.files }}"
72 when: ansible_distribution == "Ubuntu"