Merge "Change CivetWeb download URL"
[yardstick.git] / ansible / roles / enable_iommu_on_boot / tasks / main.yml
1 # Copyright (c) 2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 ---
15 - name: Set iommu_boot_params for Intel
16   set_fact:
17     iommu_boot_params: ' intel_iommu=on iommu=pt'
18   when: hostvars[inventory_hostname]['ansible_system_vendor'] == "Intel Corporation"
19
20 - name: Set iommu_boot_params for AMD
21   set_fact:
22     iommu_boot_params: ' amd_iommu=on iommu=pt'
23   when: hostvars[inventory_hostname]['ansible_system_vendor'] == "AuthenticAMD"
24
25 - name: Set facts for this role
26   set_fact:
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 }}'
33
34 - name: check if iommu is set by this role in /etc/default/grub
35   lineinfile:
36     path: /etc/default/grub
37     line: '{{ iommu_enabled_kernel_params_with_help }}'
38   #changed_when: no
39   check_mode: yes
40   register: is_mine_iommu_etc_grub
41   ignore_errors: True
42
43 - name: check if iommu is set by someone else
44   command: "grep -o 'iommu' /etc/default/grub"
45   register: is_iommu
46   ignore_errors: True
47
48 - fail:
49     msg: "Iommu already set by someone else"
50   when: is_mine_iommu_etc_grub.changed == false and is_iommu.stdout != ""
51
52 - name: 'Configure iommu in /etc/default/grub'
53 # and /boot/grub/grub.cfg(when: ansible_distribution == "Ubuntu")'
54   lineinfile:
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 }}'
58     backrefs: yes
59   when: is_mine_iommu_etc_grub.changed == true
60
61 - name: find boot grub.cfg
62   find:
63     paths: /boot
64     file_type: file
65     patterns: 'grub*.cfg'
66     recurse: yes
67   register: grub_files
68
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"