Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 1 | --- |
| 2 | # file: create-vms/tasks/main.yml |
| 3 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 4 | - 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: |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 13 | name: "{{ item.name }}" |
| 14 | command: autostart |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 15 | with_items: "{{ head_vm_list }}" |
| 16 | |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 17 | - name: fetch IP of DHCP harvester |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 18 | when: on_maas |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 19 | command: docker-ip harvester |
| 20 | register: harvester_ip |
| 21 | changed_when: False |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 22 | |
| 23 | - name: force a harvest to get VM name resolution |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 24 | when: on_maas |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 25 | uri: |
| 26 | url: http://{{ harvester_ip.stdout }}:8954/harvest |
| 27 | method: POST |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 28 | |
| 29 | - name: wait for VM name resolution |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 30 | when: on_maas |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 31 | host_dns_check: |
| 32 | hosts: "{{ head_vm_list | map(attribute='name') | list }}" |
| 33 | command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest" |
| 34 | register: all_resolved |
| 35 | until: all_resolved.everyone == "OK" |
| 36 | retries: 5 |
| 37 | delay: 10 |
| 38 | failed_when: all_resolved.everyone != "OK" |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 39 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 40 | - 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 Bavier | 42eeab6 | 2016-07-01 16:48:57 -0400 | [diff] [blame] | 58 | - name: Update apt cache |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 59 | command: ansible services -m apt -b -u ubuntu -a "update_cache=yes cache_valid_time=3600" |
| 60 | |
| 61 | - name: Update software in all the VMs |
| 62 | when: run_dist_upgrade |
| 63 | command: ansible services -m apt -b -u ubuntu -a "upgrade=dist" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 64 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 65 | - name: Create VM's eth0 interface config file for DNS config via resolvconf program |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 66 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 67 | template: |
| 68 | src=eth0.cfg.j2 |
| 69 | dest={{ ansible_user_dir }}/eth0.cfg |
| 70 | |
| 71 | - name: Copy eth0 interface config file to all VMs |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 72 | when: not on_maas |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 73 | 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 Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 74 | |
| 75 | - name: Restart eth0 interface on all VMs |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 76 | when: not on_maas |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 77 | command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 78 | |
| 79 | - name: Verify that we can log into every VM after restarting network interfaces |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 80 | when: not on_maas |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 81 | command: ansible services -m ping -u ubuntu |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 82 | |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 83 | # sshkey is registered in head-prep task |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 84 | - name: Enable root ssh login on VM's that require it |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 85 | command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'" |
| 86 | with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}" |
| 87 | |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 88 | - name: Copy over docker installation playbook and docker apt-key |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 89 | copy: |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 90 | src="{{ item }}" |
| 91 | dest="{{ ansible_user_dir }}/{{ item }}" |
| 92 | with_items: |
| 93 | - "docker-install-playbook.yml" |
| 94 | - "docker_apt_key.gpg" |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 95 | |
| 96 | - name: Install docker in VM's that require it |
Zack Williams | 9e74c4a | 2016-05-21 10:00:03 -0700 | [diff] [blame] | 97 | command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml" |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 98 | |