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 | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 4 | - name: Check to see if we already have a uvtool image |
| 5 | find: |
| 6 | path: "/var/lib/uvtool/libvirt/images" |
| 7 | patterns: "x-uvt-b64-*" |
| 8 | register: uvtool_image |
| 9 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 10 | - name: Get ubuntu image for uvtool |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 11 | when: "{{ uvtool_image.matched < 1 }}" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 12 | command: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily \ |
| 13 | release={{ ansible_distribution_release }} arch=amd64 |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 14 | args: |
| 15 | creates: "/var/lib/uvtool/libvirt/images/x-uvt-b64-*" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 16 | async: 1200 |
| 17 | poll: 0 |
| 18 | register: uvt_sync |
| 19 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 20 | - name: collect libvirt network facts |
| 21 | virt_net: |
| 22 | command=facts |
| 23 | |
| 24 | - name: Tear down libvirt's default network |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 25 | when: not on_maas and ansible_libvirt_networks["default"] is defined |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 26 | virt_net: |
| 27 | command={{ item }} |
| 28 | name=default |
| 29 | with_items: |
| 30 | - destroy |
| 31 | - undefine |
| 32 | |
| 33 | # note, this isn't idempotent, so may need manual fixing if it changes |
| 34 | - name: define libvirt networks IP/DHCP/DNS settings |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 35 | when: not on_maas |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 36 | virt_net: |
| 37 | name=xos-{{ item.name }} |
| 38 | command=define |
| 39 | xml='{{ lookup("template", "virt_net.xml.j2") }}' |
| 40 | with_items: '{{ virt_nets }}' |
| 41 | |
Zack Williams | 351c668 | 2016-04-12 10:32:38 -0700 | [diff] [blame] | 42 | - name: collect libvirt network facts after defining new network |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 43 | when: not on_maas |
Zack Williams | 351c668 | 2016-04-12 10:32:38 -0700 | [diff] [blame] | 44 | virt_net: |
| 45 | command=facts |
| 46 | |
Zack Williams | 81470de | 2016-04-11 12:44:38 -0700 | [diff] [blame] | 47 | - name: start libvirt networks |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 48 | 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] | 49 | virt_net: |
| 50 | name=xos-{{ item.name }} |
| 51 | command=create |
| 52 | with_items: '{{ virt_nets }}' |
| 53 | |
| 54 | - name: have libvirt networks autostart |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 55 | 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] | 56 | virt_net: |
| 57 | name=xos-{{ item.name }} |
| 58 | autostart=yes |
| 59 | with_items: '{{ virt_nets }}' |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 60 | |
Zack Williams | 682450e | 2016-11-19 09:04:41 -0700 | [diff] [blame] | 61 | |
| 62 | - name: Have libvirt enable port forwarding to VM's |
| 63 | become: yes |
| 64 | template: |
| 65 | src={{ item }}.j2 |
| 66 | dest=/etc/libvirt/hooks/{{ item }} |
| 67 | mode=0755 owner=root |
| 68 | with_items: |
| 69 | - daemon |
| 70 | - qemu |
| 71 | notify: |
| 72 | - reload libvirt-bin |
| 73 | - run qemu hook |
| 74 | when: not on_maas |
| 75 | |
Zack Williams | c3cde84 | 2016-05-20 12:02:33 -0700 | [diff] [blame] | 76 | - name: Wait for uvt-kvm image to be available |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 77 | when: "{{ uvtool_image.matched < 1 }}" |
Zack Williams | c3cde84 | 2016-05-20 12:02:33 -0700 | [diff] [blame] | 78 | async_status: jid={{ uvt_sync.ansible_job_id }} |
| 79 | register: uvt_sync_result |
| 80 | until: uvt_sync_result.finished |
| 81 | delay: 10 |
| 82 | retries: 120 |