Merge "Adding Istio rbac roles for multicloud-k8s"
[multicloud/k8s.git] / kud / deployment_infra / playbooks / preconfigure-sriov.yml
1 ---
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 - hosts: kube-node
12   become: yes
13   pre_tasks:
14     - name: Create SRIOV driver folder in the target destination
15       file:
16         state: directory
17         path: "{{ item }}"
18       with_items:
19         - sriov
20     - copy:
21         src: "{{ playbook_dir }}/sriov_hardware_check.sh"
22         dest: sriov
23     - name: Changing perm of "sh", adding "+x"
24       shell: "chmod +x sriov_hardware_check.sh"
25       args:
26         chdir: "sriov"
27         warn: False
28     - name: Register SRIOV
29       shell: "echo {{ SRIOV | default(False) }}"
30     - name: Run the script and Re-evaluate the variable
31       command: sriov/sriov_hardware_check.sh
32       register: output
33     - set_fact:
34         _SRIOV: "{{ output.stdout }}"
35     - name: Recreate the conf file for every host
36       file:
37         path: /tmp/sriov.conf
38         state: absent
39       delegate_to: localhost
40     - lineinfile : >
41        dest=/tmp/sriov.conf
42        create=yes
43        line='{{_SRIOV}}'
44       delegate_to: localhost
45     - name: Clean the script and folder.
46       file:
47         path: sriov
48         state: absent
49
50 # Run the following task only if the SRIOV is set to True
51 # i.e when SRIOV hardware is available
52 - hosts: localhost
53   become: yes
54   pre_tasks:
55     - name: Read SRIOV value from the conf file.
56       command: cat /tmp/sriov.conf
57       register: installer_output
58       become: yes
59     - set_fact:
60         SRIOV_NODE: "{{ installer_output.stdout }}"
61     - name: Load kud variables
62       include_vars:
63         file: kud-vars.yml
64       when: SRIOV_NODE
65   tasks:
66     - name: Create sriov folder
67       file:
68         state: directory
69         path: "{{ sriov_dest }}"
70       ignore_errors: yes
71       when: SRIOV_NODE
72     - name: Get SRIOV compatible driver
73       get_url: "url={{ driver_url }}  dest=/tmp/{{ package }}.tar.gz"
74       when: SRIOV_NODE
75     - name: Extract sriov source code
76       unarchive:
77          src: "/tmp/{{ package }}.tar.gz"
78          dest: "{{ sriov_dest }}"
79       when: SRIOV_NODE
80     - name: Build the default target
81       make:
82         chdir: "/tmp/sriov/{{ package }}/src"
83       become: yes
84       when: SRIOV_NODE
85 # Copy all the driver and install script into target node
86 - hosts: kube-node
87   become: yes
88   pre_tasks:
89     - name: Load kud variables
90       include_vars:
91         file: kud-vars.yml
92       when: _SRIOV
93   tasks:
94     - name: create SRIOV driver folder in the target destination
95       file:
96         state: directory
97         path: "{{ item }}"
98       with_items:
99         - sriov_driver
100       when: _SRIOV
101     - copy:
102         src: "{{ sriov_dest }}/{{ package }}/src/iavf.ko"
103         dest: sriov_driver
104         remote_src: no
105       when: _SRIOV
106     - copy:
107         src: "{{ playbook_dir }}/install_iavf_drivers.sh"
108         dest: sriov_driver/install.sh
109         remote_src: no
110       when: _SRIOV
111     - name: Changing perm of "install.sh", adding "+x"
112       file: dest=sriov_driver/install.sh mode=a+x
113       when: _SRIOV
114     - name: Run a script with arguments
115       shell: ./install.sh
116       args:
117         chdir: "sriov_driver"
118       when: _SRIOV