2 ## Copyright (c) 2020-2021 Intel Corporation.
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
8 ## http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 with_dict: "{{ item.sriov_vfs | default({}) | combine({'default': item.default_vf_driver}) }}"
30 - name: pre-create empty dict for VFs
34 - name: populate VFs dict with values
36 vfs_acc: "{{ vfs_acc | combine({idx : item.default_vf_driver}) }}"
37 loop: "{{ range(item.sriov_numvfs | default(0) | int) | list }}"
42 - name: update VFs dict with default drivers
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') }}"
49 when: ansible_loop.index < (item.sriov_numvfs | default(0) | int )
51 # get a list of VFs PCI addresses and save the configuration
52 - name: attach VFs driver
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"
61 - name: save VF driver binding
63 path: "{{ sriov_config_path }}/bmra_interfaces"
64 line: "{{ this_item[0] }} {{ this_item[1].value }}"
65 regexp: "^{{ this_item[0] }}"
70 loop: "{{ vf_pciids.stdout_lines | zip(vfs_acc | dict2items) | list }}"
74 - vf_pciids.stderr|length == 0
75 - vf_pciids.stdout_lines|length > 0
76 when: shell_result.results | sum(attribute='rc') == 0