Hyunsun Moon | 4f9c1cd | 2021-06-03 09:15:55 -0700 | [diff] [blame^] | 1 | --- |
| 2 | # sriov tasks/main.yml |
| 3 | # |
| 4 | # SPDX-FileCopyrightText: © 2021 Open Networking Foundation <support@opennetworking.org> |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
| 7 | - name: include OS-specific vars |
| 8 | include_vars: "{{ ansible_os_family }}.yml" |
| 9 | |
| 10 | - name: include OS-specific tasks |
| 11 | include_tasks: "{{ ansible_os_family }}.yml" |
| 12 | |
| 13 | - name: Ensure VT-d is enabled in BIOS |
| 14 | tags: molecule-notest |
| 15 | shell: "set -o pipefail && dmesg | grep DMAR-IR" |
| 16 | args: |
| 17 | executable: /bin/bash |
| 18 | register: check_vt_d |
| 19 | changed_when: check_vt_d.rc != 0 |
| 20 | failed_when: check_vt_d.rc != 0 |
| 21 | |
| 22 | - name: Load vfio_pci module to the kernel |
| 23 | modprobe: |
| 24 | name: vfio_pci |
| 25 | state: present |
| 26 | when: ansible_kernel is version('5.4','<') |
| 27 | |
| 28 | - name: Set the vfio_pci module to load on boot |
| 29 | lineinfile: |
| 30 | dest: /etc/modules-load.d/vfio_pci.conf |
| 31 | create: true |
| 32 | regexp: "^vfio_pci" |
| 33 | line: "vfio_pci" |
| 34 | mode: 0644 |
| 35 | when: ansible_kernel is version('5.4','<') |
| 36 | |
| 37 | - name: Create sriov system service |
| 38 | template: |
| 39 | src: "{{ item.src }}" |
| 40 | dest: "{{ item.dest }}" |
| 41 | mode: "{{ item.mode }}" |
| 42 | owner: root |
| 43 | group: root |
| 44 | loop: |
| 45 | - {src: 'sriov', dest: '/etc/default/sriov', mode: 644} |
| 46 | - {src: 'sriov.sh.j2', dest: '/usr/local/bin/sriov.sh', mode: 'a+x'} |
| 47 | - {src: 'sriov.service.j2', dest: '/etc/systemd/system/sriov.service', mode: 644} |
| 48 | notify: enable sriov.service |
| 49 | |
| 50 | - name: Flush handlers |
| 51 | meta: flush_handlers |
| 52 | |
| 53 | - name: Add kernel boot parameters to the grub |
| 54 | lineinfile: |
| 55 | dest: /etc/default/grub |
| 56 | regexp: '^GRUB_CMDLINE_LINUX="(?!.* {{ item.regex }})(.*)"' |
| 57 | line: 'GRUB_CMDLINE_LINUX="\1 {{ item.context }}"' |
| 58 | state: present |
| 59 | backrefs: true |
| 60 | loop: |
| 61 | - {regex: 'intel_iommu=', context: 'intel_iommu=on'} |
| 62 | - {regex: 'transparent_hugepage=', context: 'transparent_hugepage=never'} |
| 63 | - {regex: 'default_hugepagesz=', context: 'default_hugepagesz=1G'} |
| 64 | - {regex: 'hugepagesz=1G', context: 'hugepagesz=1G hugepages={{ sriov_1g_hugepages }}'} |
| 65 | notify: update grub |