Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 1 | --- |
Zack Williams | 99dcc1c | 2016-04-14 07:02:57 -0700 | [diff] [blame] | 2 | # roles/config-virt-net/tasks/main.yml |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 3 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 4 | - name: collect libvirt network facts |
| 5 | virt_net: |
| 6 | command=facts |
| 7 | |
| 8 | - name: Tear down libvirt's default network |
| 9 | when: ansible_libvirt_networks["default"] is defined |
| 10 | virt_net: |
| 11 | command={{ item }} |
| 12 | name=default |
| 13 | with_items: |
| 14 | - destroy |
| 15 | - undefine |
| 16 | |
| 17 | # note, this isn't idempotent, so may need manual fixing if it changes |
| 18 | - name: define libvirt networks IP/DHCP/DNS settings |
| 19 | virt_net: |
| 20 | name=xos-{{ item.name }} |
| 21 | command=define |
| 22 | xml='{{ lookup("template", "virt_net.xml.j2") }}' |
| 23 | with_items: '{{ virt_nets }}' |
| 24 | |
Zack Williams | 351c668 | 2016-04-12 10:32:38 -0700 | [diff] [blame] | 25 | - name: collect libvirt network facts after defining new network |
| 26 | virt_net: |
| 27 | command=facts |
| 28 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 29 | - name: start libvirt networks |
| 30 | when: ansible_libvirt_networks["xos-{{ item.name }}"].state != "active" |
| 31 | virt_net: |
| 32 | name=xos-{{ item.name }} |
| 33 | command=create |
| 34 | with_items: '{{ virt_nets }}' |
| 35 | |
| 36 | - name: have libvirt networks autostart |
| 37 | when: ansible_libvirt_networks["xos-{{ item.name }}"].autostart != "yes" |
| 38 | virt_net: |
| 39 | name=xos-{{ item.name }} |
| 40 | autostart=yes |
| 41 | with_items: '{{ virt_nets }}' |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 42 | |
| 43 | - name: Have libvirt enable port forwarding to VM's |
| 44 | become: yes |
| 45 | template: |
| 46 | src={{ item }}.j2 |
| 47 | dest=/etc/libvirt/hooks/{{ item }} |
| 48 | mode=0755 owner=root |
| 49 | with_items: |
| 50 | - daemon |
| 51 | - qemu |
| 52 | notify: |
| 53 | - reload libvirt-bin |
| 54 | - run qemu hook |
| 55 | |