blob: 09d23d39407ae1d5dbfb84f65917a71ebf92f8d9 [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
17- name: wait for VM's to come up
18 wait_for:
19 host={{ item.name }}
20 port=22
21 with_items: "{{ head_vm_list }}"
22
23- name: Create /etc/ansible/hosts file
24 become: yes
25 template:
26 src=ansible_hosts.j2
27 dest=/etc/ansible/hosts
28
29- name: Verify that we can log into every VM
30 command: ansible services -m ping -u ubuntu
31
32- name: Have VM's use the apt-cache
33 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') }}\"; };'"
34
Andy Bavier42eeab62016-07-01 16:48:57 -040035- name: Update apt cache
36 command: ansible services -m apt -b -u ubuntu -a "update_cache=yes"
Zack Williamsa3e40562016-07-05 12:05:39 -070037
Zack Williamsd31bbc92016-05-20 11:43:18 -070038- name: Create VM's eth0 interface config file for DNS config via resolvconf program
39 template:
40 src=eth0.cfg.j2
41 dest={{ ansible_user_dir }}/eth0.cfg
Andy Bavierfc43e842016-07-14 13:01:45 +020042 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070043
44- name: Copy eth0 interface config file to all VMs
45 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 Bavierfc43e842016-07-14 13:01:45 +020046 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070047
48- name: Restart eth0 interface on all VMs
49 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Andy Bavierfc43e842016-07-14 13:01:45 +020050 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070051
52- name: Verify that we can log into every VM after restarting network interfaces
53 command: ansible services -m ping -u ubuntu
Andy Bavierfc43e842016-07-14 13:01:45 +020054 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070055
Zack Williams2cffa0f2016-05-20 12:18:47 -070056# sshkey is registered in head-prep task
Zack Williamse4fbacc2016-05-21 07:18:43 -070057- name: Enable root ssh login on VM's that require it
Zack Williams2cffa0f2016-05-20 12:18:47 -070058 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
59 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
60
Zack Williams7d6747d2016-06-20 10:38:59 -070061- name: Copy over docker installation playbook and docker apt-key
Zack Williamse4fbacc2016-05-21 07:18:43 -070062 copy:
Zack Williams7d6747d2016-06-20 10:38:59 -070063 src="{{ item }}"
64 dest="{{ ansible_user_dir }}/{{ item }}"
65 with_items:
66 - "docker-install-playbook.yml"
67 - "docker_apt_key.gpg"
Zack Williamse4fbacc2016-05-21 07:18:43 -070068
69- name: Install docker in VM's that require it
Zack Williams9e74c4a2016-05-21 10:00:03 -070070 command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml"