blob: 15e52e5b8c26762e0c65b2e1d10062317f942249 [file] [log] [blame]
Zack Williamsa1f55082017-02-28 22:41:36 -07001---
2# virt-nets/tasks/main.yml
3
4- name: Install libvirt/lxml python module
5 apt:
6 name: "{{ item }}"
7 update_cache: yes
8 cache_valid_time: 3600
9 with_items:
10 - python-libvirt
11 - python-lxml
12
13- name: collect libvirt network facts
14 virt_net:
15 command: facts
16
17- name: Tear down libvirt's default network
18 when: ansible_libvirt_networks["default"] is defined
19 virt_net:
20 command: "{{ item }}"
21 name: "default"
22 with_items:
23 - destroy
24 - undefine
25
26# note, this isn't idempotent, so may need manual fixing if it changes
27- name: Define libvirt networks settings (IP/DHCP/DNS)
28 when: "{{ ansible_libvirt_networks[item.name] is not defined }}"
29 virt_net:
30 name: "{{ item.name }}"
31 command: define
32 xml: "{{ lookup('template', 'virt_net.xml.j2') }}"
33 with_items: "{{ virt_nets }}"
34
35- name: Collect libvirt network facts after defining new network
36 virt_net:
37 command: facts
38
39- name: Start libvirt networks
40 when: "{{ ansible_libvirt_networks[item.name].state != 'active' }}"
41 virt_net:
42 name: "{{ item.name }}"
43 command: create
44 autostart: yes
45 with_items: "{{ virt_nets }}"
46
47- name: Have libvirt networks automatically start on reboot
48 when: "{{ ansible_libvirt_networks[item.name].autostart != 'yes' }}"
49 virt_net:
50 name: "{{ item.name }}"
51 autostart: yes
52 with_items: "{{ virt_nets }}"
53