blob: 038a5ce5d78b2704f9b106bdbca7d256ff8b5d35 [file] [log] [blame]
Zack Williamsd31bbc92016-05-20 11:43:18 -07001---
2# file: create-vms/tasks/main.yml
3
Zack Williamsd31bbc92016-05-20 11:43:18 -07004- name: create Virtual Machines with uvt-kvm
5 shell: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \
6 --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr"
7 creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow
8 with_items: "{{ head_vm_list }}"
9
10- name: Have VMs autostart on reboot
11 become: yes
12 virt:
13 name={{ item.name }}
14 command=autostart
15 with_items: "{{ head_vm_list }}"
16
David K. Bainbridged3da6082016-08-11 14:01:27 -070017- name: fetch IP of DHCP harvester
18 command: docker-ip harvester
19 register: harvester_ip
20 changed_when: False
21 when: on_maas
22
23- name: force a harvest to get VM name resolution
24 uri:
25 url: http://{{ harvester_ip.stdout }}:8954/harvest
26 method: POST
27 when: on_maas
28
29- name: wait for VM name resolution
30 host_dns_check:
31 hosts: "{{ head_vm_list | map(attribute='name') | list }}"
32 command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
33 register: all_resolved
34 until: all_resolved.everyone == "OK"
35 retries: 5
36 delay: 10
37 failed_when: all_resolved.everyone != "OK"
38 when: on_maas
39
Zack Williamsd31bbc92016-05-20 11:43:18 -070040- name: wait for VM's to come up
41 wait_for:
42 host={{ item.name }}
43 port=22
44 with_items: "{{ head_vm_list }}"
45
46- name: Create /etc/ansible/hosts file
47 become: yes
48 template:
49 src=ansible_hosts.j2
50 dest=/etc/ansible/hosts
51
52- name: Verify that we can log into every VM
53 command: ansible services -m ping -u ubuntu
54
55- name: Have VM's use the apt-cache
56 command: ansible services -b -u ubuntu -m lineinfile -a "dest=/etc/apt/apt.conf.d/02apt-cacher-ng create=yes mode=0644 owner=root group=root regexp='^Acquire' line='Acquire::http { Proxy \"http://{{ apt_cacher_name }}:{{ apt_cacher_port | default('3142') }}\"; };'"
57
Andy Bavier42eeab62016-07-01 16:48:57 -040058- name: Update apt cache
59 command: ansible services -m apt -b -u ubuntu -a "update_cache=yes"
Zack Williamsa3e40562016-07-05 12:05:39 -070060
Zack Williamsd31bbc92016-05-20 11:43:18 -070061- name: Create VM's eth0 interface config file for DNS config via resolvconf program
62 template:
63 src=eth0.cfg.j2
64 dest={{ ansible_user_dir }}/eth0.cfg
Andy Bavier0481a8a2016-07-14 13:01:45 +020065 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070066
67- name: Copy eth0 interface config file to all VMs
68 command: ansible services -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/eth0.cfg dest=/etc/network/interfaces.d/eth0.cfg owner=root group=root mode=0644"
Andy Bavier0481a8a2016-07-14 13:01:45 +020069 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070070
71- name: Restart eth0 interface on all VMs
72 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Andy Bavier0481a8a2016-07-14 13:01:45 +020073 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070074
75- name: Verify that we can log into every VM after restarting network interfaces
76 command: ansible services -m ping -u ubuntu
Andy Bavier0481a8a2016-07-14 13:01:45 +020077 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070078
Zack Williams2cffa0f2016-05-20 12:18:47 -070079# sshkey is registered in head-prep task
Zack Williamse4fbacc2016-05-21 07:18:43 -070080- name: Enable root ssh login on VM's that require it
Zack Williams2cffa0f2016-05-20 12:18:47 -070081 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
82 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
83
Zack Williams7d6747d2016-06-20 10:38:59 -070084- name: Copy over docker installation playbook and docker apt-key
Zack Williamse4fbacc2016-05-21 07:18:43 -070085 copy:
Zack Williams7d6747d2016-06-20 10:38:59 -070086 src="{{ item }}"
87 dest="{{ ansible_user_dir }}/{{ item }}"
88 with_items:
89 - "docker-install-playbook.yml"
90 - "docker_apt_key.gpg"
Zack Williamse4fbacc2016-05-21 07:18:43 -070091
92- name: Install docker in VM's that require it
Zack Williams9e74c4a2016-05-21 10:00:03 -070093 command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml"