blob: ef238b4e430ee8f12715df63444129d3cd93c07b [file] [log] [blame]
Matteo Scandolo60b640f2017-08-08 13:05:22 -07001
2# Copyright 2017-present Open Networking Foundation
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15
16
Zack Williamsa1f55082017-02-28 22:41:36 -070017---
18# virt-nets/tasks/main.yml
19
20- name: Install libvirt/lxml python module
21 apt:
22 name: "{{ item }}"
23 update_cache: yes
24 cache_valid_time: 3600
25 with_items:
26 - python-libvirt
27 - python-lxml
28
29- name: collect libvirt network facts
30 virt_net:
31 command: facts
32
33- name: Tear down libvirt's default network
34 when: ansible_libvirt_networks["default"] is defined
35 virt_net:
36 command: "{{ item }}"
37 name: "default"
38 with_items:
39 - destroy
40 - undefine
41
42# note, this isn't idempotent, so may need manual fixing if it changes
43- name: Define libvirt networks settings (IP/DHCP/DNS)
44 when: "{{ ansible_libvirt_networks[item.name] is not defined }}"
45 virt_net:
46 name: "{{ item.name }}"
47 command: define
48 xml: "{{ lookup('template', 'virt_net.xml.j2') }}"
49 with_items: "{{ virt_nets }}"
50
51- name: Collect libvirt network facts after defining new network
52 virt_net:
53 command: facts
54
55- name: Start libvirt networks
56 when: "{{ ansible_libvirt_networks[item.name].state != 'active' }}"
57 virt_net:
58 name: "{{ item.name }}"
59 command: create
60 autostart: yes
61 with_items: "{{ virt_nets }}"
62
63- name: Have libvirt networks automatically start on reboot
64 when: "{{ ansible_libvirt_networks[item.name].autostart != 'yes' }}"
65 virt_net:
66 name: "{{ item.name }}"
67 autostart: yes
68 with_items: "{{ virt_nets }}"
69