blob: 593386ee3ffd902baf145afcef10a581d7992289 [file] [log] [blame]
Hyunsun Moone4848342020-02-16 04:28:55 -08001# Copyright 2020-present Open Networking Foundation
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---
16# Fail if VT-d is not enabled
17- name: Ensure VT-d is enabled in BIOS
Hyunsun Moon6c6db952020-03-04 20:50:51 -080018 shell: "set -o pipefail && dmesg | grep DMAR-IR"
19 args:
20 executable: /bin/bash
Hyunsun Moone4848342020-02-16 04:28:55 -080021 register: check_vt_d
22 changed_when: check_vt_d.rc != 0
23 failed_when: check_vt_d.rc != 0
24 tags: sriov-dpdk
25
26- name: Add kernel boot parameters to the grub for SRIOV
27 lineinfile:
28 dest: /etc/default/grub
29 regexp: '^GRUB_CMDLINE_LINUX="(?!.* {{ item.regex }})(.*)"'
30 line: 'GRUB_CMDLINE_LINUX="\1 {{ item.context }}"'
31 state: present
32 backrefs: yes
33 loop:
34 - { regex: 'intel_iommu=on', context: 'intel_iommu=on' }
35 - { regex: 'hugepagesz=', context: 'hugepagesz=1G default_hugepagesz=1G hugepages=32' }
36 register: grub
Hyunsun Moon6c6db952020-03-04 20:50:51 -080037 notify: update grub
Hyunsun Moone4848342020-02-16 04:28:55 -080038 tags: sriov-dpdk
39
40- name: Load vfio_pci module to the kernel
41 modprobe:
42 name: vfio_pci
43 state: present
44 tags: sriov-dpdk
45
46- name: Set the vfio_pci module to load on boot
47 lineinfile:
48 dest: /etc/modules-load.d/vfio_pci.conf
49 create: yes
50 regexp: "^vfio_pci"
51 line: "vfio_pci"
52 tags: sriov-dpdk
53
54- name: Check VFIO bind devices for DPDK
Hyunsun Moon6c6db952020-03-04 20:50:51 -080055 shell: "set -o pipefail && ls -l /dev/vfio | wc -l"
56 args:
57 executable: /bin/bash
Hyunsun Moone4848342020-02-16 04:28:55 -080058 register: check_dpdk_bind
Hyunsun Moon6c6db952020-03-04 20:50:51 -080059 changed_when: False
Hyunsun Moone4848342020-02-16 04:28:55 -080060 tags: sriov-dpdk
61
62- name: Create SRIOV-DPDK service
63 template:
64 src: "{{ item.src }}"
65 dest: "{{ item.dest }}"
66 mode: "{{ item.mode }}"
67 loop:
68 - { src: 'usr/bin/sriov.sh.j2', dest: '/usr/bin/sriov.sh', mode: 'a+x' }
69 - { src: 'etc/systemd/system/sriov.service.j2', dest: '/etc/systemd/system/sriov.service', mode: 644 }
70 register: bind_dpdk
Hyunsun Moon6c6db952020-03-04 20:50:51 -080071 notify: enable sriov
Hyunsun Moone4848342020-02-16 04:28:55 -080072 when: check_dpdk_bind.stdout | int < 4
73 tags: sriov-dpdk
74
Hyunsun Moon6c6db952020-03-04 20:50:51 -080075- meta: flush_handlers
Hyunsun Moone4848342020-02-16 04:28:55 -080076 tags: sriov-dpdk
77
78- name: Reboot machine
79 shell: sleep 2 && shutdown -r now "Ansible updates triggered"
80 async: 1
81 poll: 0
82 ignore_errors: true
Hyunsun Moon6c6db952020-03-04 20:50:51 -080083 when: grub.changed or bind_dpdk.changed # noqa 503
Hyunsun Moone4848342020-02-16 04:28:55 -080084 tags: sriov-dpdk
85
Hyunsun Moon6c6db952020-03-04 20:50:51 -080086- name: Wait for server to restart
Hyunsun Moone4848342020-02-16 04:28:55 -080087 wait_for:
88 host: "{{ ansible_host }}"
89 search_regex: "OpenSSH"
90 port: 22
91 timeout: 300
92 connect_timeout: 50
93 delay: 5
94 delegate_to: localhost
95 become: false
96 tags: sriov-dpdk
97
98- name: Ensure enough VFIO bind devices
Hyunsun Moon6c6db952020-03-04 20:50:51 -080099 shell: "set -o pipefail && ls -l /dev/vfio | wc -l"
100 args:
101 executable: /bin/bash
Hyunsun Moone4848342020-02-16 04:28:55 -0800102 register: confirm_dpdk_bind
103 changed_when: confirm_dpdk_bind.stdout | int < 4
104 failed_when: confirm_dpdk_bind.stdout | int < 4
105 tags: sriov-dpdk