sriovdp_config: Improvements and fixes
[ta/infra-ansible.git] / roles / sriovdp_config / tasks / main.yaml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 - name: collect network device PCI addresses
18   shell: dpdk-devbind --status-dev net | egrep "^[0-9a-fA-F]{4}\b.*if=" || true
19   register: devbind
20
21 - set_fact:
22     pci: []
23     iface: []
24
25 - set_fact:
26     pci: "{{ pci }} + {{ [ item.split()[0][:12] ] }}"
27     iface: "{{ iface }} + {{ [ item.split(' if=')[1].split()[0] ] }}"
28   with_items: "{{ devbind.stdout_lines }}"
29
30 - set_fact:
31     ifacepcimap: "{{ dict( iface | zip(pci) ) }}"
32
33 - debug: var=ifacepcimap
34
35 - name: "create {{ sriovdp_config_path }} directory"
36   file:
37     path: "{{ sriovdp_config_path }}"
38     mode: "0700"
39     state: directory
40
41 - name: "create {{ sriovdp_config_path }}config.yaml"
42   template:
43     src: sriovdp_config.yaml.j2
44     dest: "{{ sriovdp_config_path }}config.yaml"
45
46 - name: "convert {{ sriovdp_config_path }}config.yaml to config.json"
47   shell: "python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' <{{ sriovdp_config_path }}config.yaml >{{ sriovdp_config_path }}config.json"
48
49 - name: limit file permissions to root user
50   file:
51     path: "{{ item }}"
52     state: file
53     mode: "0600"
54   with_fileglob: "{{ sriovdp_config_path }}*"