blob: 7b70b0f68dbc18d90c3192db702627b952c7b4ad [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
18 shell: "dmesg | grep DMAR-IR"
19 register: check_vt_d
20 changed_when: check_vt_d.rc != 0
21 failed_when: check_vt_d.rc != 0
22 tags: sriov-dpdk
23
24- name: Add kernel boot parameters to the grub for SRIOV
25 lineinfile:
26 dest: /etc/default/grub
27 regexp: '^GRUB_CMDLINE_LINUX="(?!.* {{ item.regex }})(.*)"'
28 line: 'GRUB_CMDLINE_LINUX="\1 {{ item.context }}"'
29 state: present
30 backrefs: yes
31 loop:
32 - { regex: 'intel_iommu=on', context: 'intel_iommu=on' }
33 - { regex: 'hugepagesz=', context: 'hugepagesz=1G default_hugepagesz=1G hugepages=32' }
34 register: grub
35 tags: sriov-dpdk
36
37- name: Update grub
38 command: update-grub
39 when: grub.changed
40 register: update_grub
41 tags: sriov-dpdk
42
43- name: Load vfio_pci module to the kernel
44 modprobe:
45 name: vfio_pci
46 state: present
47 tags: sriov-dpdk
48
49- name: Set the vfio_pci module to load on boot
50 lineinfile:
51 dest: /etc/modules-load.d/vfio_pci.conf
52 create: yes
53 regexp: "^vfio_pci"
54 line: "vfio_pci"
55 tags: sriov-dpdk
56
57- name: Check VFIO bind devices for DPDK
58 shell: "ls -l /dev/vfio | wc -l"
59 register: check_dpdk_bind
60 changed_when: check_dpdk_bind.stdout | int < 4
61 tags: sriov-dpdk
62
63- name: Create SRIOV-DPDK service
64 template:
65 src: "{{ item.src }}"
66 dest: "{{ item.dest }}"
67 mode: "{{ item.mode }}"
68 loop:
69 - { src: 'usr/bin/sriov.sh.j2', dest: '/usr/bin/sriov.sh', mode: 'a+x' }
70 - { src: 'etc/systemd/system/sriov.service.j2', dest: '/etc/systemd/system/sriov.service', mode: 644 }
71 register: bind_dpdk
72 when: check_dpdk_bind.stdout | int < 4
73 tags: sriov-dpdk
74
75- name: Enable SRIOV-DPDK service
76 systemd:
77 name: sriov
78 daemon_reload: true
79 enabled: yes
80 when: bind_dpdk.changed
81 tags: sriov-dpdk
82
83- name: Reboot machine
84 shell: sleep 2 && shutdown -r now "Ansible updates triggered"
85 async: 1
86 poll: 0
87 ignore_errors: true
88 when: update_grub.changed or bind_dpdk.changed
89 tags: sriov-dpdk
90
91- name: Wait for server to restart successfully
92 wait_for:
93 host: "{{ ansible_host }}"
94 search_regex: "OpenSSH"
95 port: 22
96 timeout: 300
97 connect_timeout: 50
98 delay: 5
99 delegate_to: localhost
100 become: false
101 tags: sriov-dpdk
102
103- name: Ensure enough VFIO bind devices
104 shell: "ls -l /dev/vfio | wc -l"
105 register: confirm_dpdk_bind
106 changed_when: confirm_dpdk_bind.stdout | int < 4
107 failed_when: confirm_dpdk_bind.stdout | int < 4
108 tags: sriov-dpdk