Initial commit
[ta/infra-ansible.git] / playbooks / baremetal-interface-config-post.yml
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 # cmframework.requires: performance_nodes_post.yaml,provisioning_done.yml
18
19 - name: Interface configuration postconfig
20   hosts: baremetal-nodes:!localhost
21   gather_facts: "{{ gather_facts | default(True) }}"
22   tasks:
23   - name: Run os-net-config command
24     command: "os-net-config --detailed-exit-codes -v -c /etc/os-net-config/config.json"
25     register: os_net_config_result
26     failed_when: not (os_net_config_result.rc == 0 or os_net_config_result.rc == 2)
27     changed_when: os_net_config_result.rc == 2
28
29   - debug: var=os_net_config_result.stderr_lines
30     when: os_net_config_result.rc == 2
31
32   - name: Get os-net-config
33     slurp:
34       src: /etc/os-net-config/config.json
35     register: os_net_config_b64
36
37   - name: Set os_net_config
38     set_fact:
39       os_net_config: "{{ os_net_config_b64['content'] | b64decode | from_json }}"
40
41   - name: Get interface names
42     set_fact:
43       phy_ifaces: "{{ os_net_config | json_query('network_config[*].name') }}"
44
45   - name: Make sure bridges are up
46     command: "ifup {{item}}"
47     with_items: "{{phy_ifaces}}"
48     ignore_errors: "yes"
49
50   - name: Updating the facts due to net changes
51     setup:
52
53   - name: Check if SR-IOV is configured
54     stat:
55       path: /etc/sriov/sriov.conf
56     register: sriov_result
57
58   - name: Enable sriov.service
59     systemd:
60       name: sriov
61       daemon_reload: "yes"
62       enabled: "yes"
63     when: sriov_result.stat.exists == True
64
65   - name: Start sriov.service
66     systemd:
67       name: sriov
68       state: started
69     when: sriov_result.stat.exists == True and hostname != installation_controller
70
71   - name: Check if OVS offload SR-IOV is configured
72     shell: grep "SRIOV_INTERFACES_OFFLOADED" /etc/sriov/sriov.conf | cut -d = -f2 | sed -e 's/^"//' -e 's/"$//'
73     register: offload_result
74     when: sriov_result.stat.exists == True
75
76   - name: Enable ovsoffloadsriov.service
77     systemd:
78       name: ovsoffloadsriov
79       daemon_reload: "yes"
80       enabled: "yes"
81     when:
82       - sriov_result.stat.exists == True
83       - offload_result.stdout != ""
84
85   - name: Start offload.service
86     systemd:
87       name: ovsoffloadsriov
88       state: started
89     when:
90       - sriov_result.stat.exists == True
91       - offload_result.stdout != "" and hostname != installation_controller
92
93 - name: Restart nova compute if sr-iov configured except on CAAS nodes
94   hosts: base:!vnf-nodes
95   gather_facts: "{{ gather_facts | default(True) }}"
96   tasks:
97   - name: Check if nova-compute service is enabled here
98     shell: "systemctl list-unit-files | grep enabled | grep -w nova-compute | wc -l"
99     register: novacomputeresult
100
101   - name: Restart nova compute
102     systemd:
103       name: nova-compute
104       state: restarted
105     when: sriov_result.stat.exists == True and hostname != installation_controller and novacomputeresult.stdout|int > 0
106