blob: 77244f012290d9e3e402015c9c95f4f8f94ee717 [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
Zack Williams35624562016-08-28 17:12:26 -07005 command: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \
Zack Williamsd31bbc92016-05-20 11:43:18 -07006 --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr"
Zack Williams35624562016-08-28 17:12:26 -07007 args:
8 creates: "/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow"
Zack Williamsd31bbc92016-05-20 11:43:18 -07009 with_items: "{{ head_vm_list }}"
10
11- name: Have VMs autostart on reboot
12 become: yes
13 virt:
Zack Williams6f5a6e72016-08-10 17:45:27 -070014 name: "{{ item.name }}"
15 command: autostart
Zack Williamsd31bbc92016-05-20 11:43:18 -070016 with_items: "{{ head_vm_list }}"
17
David K. Bainbridged3da6082016-08-11 14:01:27 -070018- name: fetch IP of DHCP harvester
Zack Williams6f5a6e72016-08-10 17:45:27 -070019 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070020 command: docker-ip harvester
21 register: harvester_ip
22 changed_when: False
David K. Bainbridged3da6082016-08-11 14:01:27 -070023
24- name: force a harvest to get VM name resolution
Zack Williams6f5a6e72016-08-10 17:45:27 -070025 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070026 uri:
27 url: http://{{ harvester_ip.stdout }}:8954/harvest
28 method: POST
David K. Bainbridged3da6082016-08-11 14:01:27 -070029
30- name: wait for VM name resolution
Zack Williams6f5a6e72016-08-10 17:45:27 -070031 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070032 host_dns_check:
33 hosts: "{{ head_vm_list | map(attribute='name') | list }}"
34 command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
35 register: all_resolved
36 until: all_resolved.everyone == "OK"
37 retries: 5
38 delay: 10
39 failed_when: all_resolved.everyone != "OK"
David K. Bainbridged3da6082016-08-11 14:01:27 -070040
Zack Williamsd31bbc92016-05-20 11:43:18 -070041- name: wait for VM's to come up
42 wait_for:
43 host={{ item.name }}
44 port=22
45 with_items: "{{ head_vm_list }}"
46
47- name: Create /etc/ansible/hosts file
48 become: yes
49 template:
50 src=ansible_hosts.j2
51 dest=/etc/ansible/hosts
52
53- name: Verify that we can log into every VM
54 command: ansible services -m ping -u ubuntu
Zack Williams35624562016-08-28 17:12:26 -070055 tags:
56 - skip_ansible_lint # connectivity check
Zack Williamsd31bbc92016-05-20 11:43:18 -070057
58- name: Have VM's use the apt-cache
59 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') }}\"; };'"
Zack Williams35624562016-08-28 17:12:26 -070060 tags:
61 - skip_ansible_lint # running a sub job
Zack Williamsd31bbc92016-05-20 11:43:18 -070062
Andy Bavier42eeab62016-07-01 16:48:57 -040063- name: Update apt cache
Zack Williams6f5a6e72016-08-10 17:45:27 -070064 command: ansible services -m apt -b -u ubuntu -a "update_cache=yes cache_valid_time=3600"
Zack Williams35624562016-08-28 17:12:26 -070065 tags:
66 - skip_ansible_lint # running a sub job
Zack Williams6f5a6e72016-08-10 17:45:27 -070067
68- name: Update software in all the VMs
69 when: run_dist_upgrade
70 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist"
Zack Williams35624562016-08-28 17:12:26 -070071 tags:
72 - skip_ansible_lint # running a sub job
Zack Williamsa3e40562016-07-05 12:05:39 -070073
Zack Williamsd31bbc92016-05-20 11:43:18 -070074- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams6f5a6e72016-08-10 17:45:27 -070075 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070076 template:
77 src=eth0.cfg.j2
78 dest={{ ansible_user_dir }}/eth0.cfg
79
80- name: Copy eth0 interface config file to all VMs
Andy Bavier0481a8a2016-07-14 13:01:45 +020081 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070082 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"
Zack Williamsd31bbc92016-05-20 11:43:18 -070083
84- name: Restart eth0 interface on all VMs
Andy Bavier0481a8a2016-07-14 13:01:45 +020085 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070086 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williamsd31bbc92016-05-20 11:43:18 -070087
88- name: Verify that we can log into every VM after restarting network interfaces
Andy Bavier0481a8a2016-07-14 13:01:45 +020089 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070090 command: ansible services -m ping -u ubuntu
Zack Williamsd31bbc92016-05-20 11:43:18 -070091
Zack Williams2cffa0f2016-05-20 12:18:47 -070092# sshkey is registered in head-prep task
Zack Williamse4fbacc2016-05-21 07:18:43 -070093- name: Enable root ssh login on VM's that require it
Zack Williams2cffa0f2016-05-20 12:18:47 -070094 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
95 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
Zack Williams35624562016-08-28 17:12:26 -070096 tags:
97 - skip_ansible_lint # FIXME, ssh key mangling
Zack Williams2cffa0f2016-05-20 12:18:47 -070098
Zack Williams7d6747d2016-06-20 10:38:59 -070099- name: Copy over docker installation playbook and docker apt-key
Zack Williamse4fbacc2016-05-21 07:18:43 -0700100 copy:
Zack Williams7d6747d2016-06-20 10:38:59 -0700101 src="{{ item }}"
102 dest="{{ ansible_user_dir }}/{{ item }}"
103 with_items:
104 - "docker-install-playbook.yml"
105 - "docker_apt_key.gpg"
Zack Williamse4fbacc2016-05-21 07:18:43 -0700106
107- name: Install docker in VM's that require it
Zack Williams9e74c4a2016-05-21 10:00:03 -0700108 command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml"
Zack Williams35624562016-08-28 17:12:26 -0700109 tags:
110 - skip_ansible_lint # running a sub job
111
Zack Williams6f5a6e72016-08-10 17:45:27 -0700112