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: |
| 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 Bavier | 42eeab6 | 2016-07-01 16:48:57 -0400 | [diff] [blame] | 35 | - name: Update apt cache |
| 36 | command: ansible services -m apt -b -u ubuntu -a "update_cache=yes" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 37 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 38 | - name: Update software in all the VMs |
Andy Bavier | 42eeab6 | 2016-07-01 16:48:57 -0400 | [diff] [blame] | 39 | command: ansible services -m apt -b -u ubuntu -a "upgrade=dist" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 40 | |
| 41 | - name: Create VM's eth0 interface config file for DNS config via resolvconf program |
| 42 | template: |
| 43 | src=eth0.cfg.j2 |
| 44 | dest={{ ansible_user_dir }}/eth0.cfg |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 45 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 46 | |
| 47 | - name: Copy eth0 interface config file to all VMs |
| 48 | 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 Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 49 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 50 | |
| 51 | - name: Restart eth0 interface on all VMs |
| 52 | command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0" |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 53 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 54 | |
| 55 | - name: Verify that we can log into every VM after restarting network interfaces |
| 56 | command: ansible services -m ping -u ubuntu |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 57 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 58 | |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 59 | # sshkey is registered in head-prep task |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 60 | - name: Enable root ssh login on VM's that require it |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 61 | command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'" |
| 62 | with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}" |
| 63 | |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 64 | - name: Copy over docker installation playbook and docker apt-key |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 65 | copy: |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 66 | src="{{ item }}" |
| 67 | dest="{{ ansible_user_dir }}/{{ item }}" |
| 68 | with_items: |
| 69 | - "docker-install-playbook.yml" |
| 70 | - "docker_apt_key.gpg" |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 71 | |
| 72 | - name: Install docker in VM's that require it |
Zack Williams | 9e74c4a | 2016-05-21 10:00:03 -0700 | [diff] [blame] | 73 | command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml" |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 74 | |