Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 1 | --- |
Zack Williams | c3cde84 | 2016-05-20 12:02:33 -0700 | [diff] [blame] | 2 | # roles/config-virt/tasks/main.yml |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 3 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 4 | - name: Get ubuntu image for uvtool |
| 5 | command: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily \ |
| 6 | release={{ ansible_distribution_release }} arch=amd64 |
| 7 | async: 1200 |
| 8 | poll: 0 |
| 9 | register: uvt_sync |
| 10 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 11 | - name: collect libvirt network facts |
| 12 | virt_net: |
| 13 | command=facts |
| 14 | |
| 15 | - name: Tear down libvirt's default network |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 16 | when: not on_maas and ansible_libvirt_networks["default"] is defined |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 17 | virt_net: |
| 18 | command={{ item }} |
| 19 | name=default |
| 20 | with_items: |
| 21 | - destroy |
| 22 | - undefine |
| 23 | |
| 24 | # note, this isn't idempotent, so may need manual fixing if it changes |
| 25 | - name: define libvirt networks IP/DHCP/DNS settings |
| 26 | virt_net: |
| 27 | name=xos-{{ item.name }} |
| 28 | command=define |
| 29 | xml='{{ lookup("template", "virt_net.xml.j2") }}' |
| 30 | with_items: '{{ virt_nets }}' |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 31 | when: not on_maas |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 32 | |
Zack Williams | 351c668 | 2016-04-12 10:32:38 -0700 | [diff] [blame] | 33 | - name: collect libvirt network facts after defining new network |
| 34 | virt_net: |
| 35 | command=facts |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 36 | when: not on_maas |
Zack Williams | 351c668 | 2016-04-12 10:32:38 -0700 | [diff] [blame] | 37 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 38 | - name: start libvirt networks |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 39 | when: not on_maas and ansible_libvirt_networks["xos-{{ item.name }}"].state != "active" |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 40 | virt_net: |
| 41 | name=xos-{{ item.name }} |
| 42 | command=create |
| 43 | with_items: '{{ virt_nets }}' |
| 44 | |
| 45 | - name: have libvirt networks autostart |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 46 | when: not on_maas and ansible_libvirt_networks["xos-{{ item.name }}"].autostart != "yes" |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 47 | virt_net: |
| 48 | name=xos-{{ item.name }} |
| 49 | autostart=yes |
| 50 | with_items: '{{ virt_nets }}' |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 51 | |
| 52 | - name: Have libvirt enable port forwarding to VM's |
| 53 | become: yes |
Andy Bavier | 9d7c09e | 2016-07-19 20:37:58 -0400 | [diff] [blame] | 54 | copy: |
| 55 | src={{ item }} |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 56 | dest=/etc/libvirt/hooks/{{ item }} |
| 57 | mode=0755 owner=root |
| 58 | with_items: |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 59 | - qemu |
| 60 | notify: |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 61 | - run qemu hook |
| 62 | |
Zack Williams | c3cde84 | 2016-05-20 12:02:33 -0700 | [diff] [blame] | 63 | - name: Wait for uvt-kvm image to be available |
| 64 | async_status: jid={{ uvt_sync.ansible_job_id }} |
| 65 | register: uvt_sync_result |
| 66 | until: uvt_sync_result.finished |
| 67 | delay: 10 |
| 68 | retries: 120 |