81d4ab564e6ab7360d21be0822589e64a3f6ce36
[kuberef.git] / sw_config / bmra / patched_vfio.yml
1 ##
2 ##   Copyright (c) 2020-2021 Intel Corporation.
3 ##
4 ##   Licensed under the Apache License, Version 2.0 (the "License");
5 ##   you may not use this file except in compliance with the License.
6 ##   You may obtain a copy of the License at
7 ##
8 ##       http://www.apache.org/licenses/LICENSE-2.0
9 ##
10 ##   Unless required by applicable law or agreed to in writing, software
11 ##   distributed under the License is distributed on an "AS IS" BASIS,
12 ##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ##   See the License for the specific language governing permissions and
14 ##   limitations under the License.
15 ##
16 ---
17 # check if the selected driver module is available on host
18 - name: Check that selected driver module is available
19   # if modinfo fails, lookup loaded modules as modinfo might return error
20   # for igb_uio and potentially other modules not included with the kernel
21   shell: "modinfo {{ vf_driver.value }} || grep {{ vf_driver.value }} /proc/modules || grep {{ vf_driver.value }} /lib/modules/$(uname -r)/modules.builtin"
22   register: shell_result
23   ignore_errors: yes
24   failed_when: no
25   changed_when: no
26   with_dict: "{{ item.sriov_vfs | default({}) | combine({'default': item.default_vf_driver}) }}"
27   loop_control:
28     loop_var: vf_driver
29
30 - name: pre-create empty dict for VFs
31   set_fact:
32     vfs_acc: {}
33
34 - name: populate VFs dict with values
35   set_fact:
36     vfs_acc: "{{ vfs_acc | combine({idx : item.default_vf_driver}) }}"
37   loop: "{{ range(item.sriov_numvfs | default(0) | int) | list }}"
38   loop_control:
39     index_var: idx
40     loop_var: vf_default
41
42 - name: update VFs dict with default drivers
43   set_fact:
44     vfs_acc: "{{ vfs_acc | combine({vf.key | regex_replace('.*_(\\d*)', '\\1') | int : vf.value}) }}"
45   loop: "{{ item.sriov_vfs | default({}) | dict2items | sort(attribute='key') }}"
46   loop_control:
47     loop_var: vf
48     extended: yes
49   when:  ansible_loop.index < (item.sriov_numvfs | default(0) | int )
50
51 # get a list of VFs PCI addresses and save the configuration
52 - name: attach VFs driver
53   block:
54     - name: fetch VFs pci addresses for a PF
55       shell: "for vf in /sys/class/net/{{ item.name }}/device/virtfn*;do basename $(readlink -f $vf);done | sort"
56       register: vf_pciids
57       args:
58         executable: /bin/bash
59       changed_when: false
60
61     - name: save VF driver binding
62       lineinfile:
63         path: "{{ sriov_config_path }}/bmra_interfaces"
64         line: "{{ this_item[0] }} {{ this_item[1].value }}"
65         regexp: "^{{ this_item[0] }}"
66         create: yes
67         owner: root
68         group: root
69         mode: '0600'
70       loop: "{{ vf_pciids.stdout_lines | zip(vfs_acc | dict2items) | list }}"
71       loop_control:
72         loop_var: this_item
73       when:
74         - vf_pciids.stderr|length == 0
75         - vf_pciids.stdout_lines|length > 0
76   when: shell_result.results | sum(attribute='rc') == 0