1 # Copyright (c) 2017-2018 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 - name: Destroy old networks created by virt
17 name: "{{ network_item.name }}"
19 when: network_item.name in virt_nets.list_nets
21 # Ignoring erros as network can be created without being defined.
22 # This can happen if a user manually creates a network using the virsh command.
23 # If the network is not defined the undefine code will throw an error.
24 - name: Undefine old networks defined by virt
26 name: "{{ network_item.name }}"
28 when: network_item.name in virt_nets.list_nets
31 - name: Check if "ovs-vsctl" command is present
32 command: which ovs-vsctl
33 register: ovs_vsctl_present
36 - name: Destroy OVS bridge if it exists
37 command: ovs-vsctl --if-exists -- del-br "{{ network_item.name }}"
38 when: ovs_vsctl_present.rc == 0
40 - name: Check if linux bridge is present
41 stat: path="{{ '/sys/class/net/'+network_item.name+'/brif/' }}"
42 register: check_linux_bridge
44 - name: Remove linux bridge if it exists
46 ifconfig "{{ network_item.name }}" down
47 brctl delbr "{{ network_item.name }}"
48 when: check_linux_bridge.stat.exists