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: 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 Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 42 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 43 | |
| 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 Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 46 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 47 | |
| 48 | - name: Restart eth0 interface on all VMs |
| 49 | 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] | 50 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 51 | |
| 52 | - name: Verify that we can log into every VM after restarting network interfaces |
| 53 | command: ansible services -m ping -u ubuntu |
Andy Bavier | fc43e84 | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 54 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 55 | |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 56 | # sshkey is registered in head-prep task |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 57 | - name: Enable root ssh login on VM's that require it |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 58 | 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 Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 61 | - name: Copy over docker installation playbook and docker apt-key |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 62 | copy: |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 63 | src="{{ item }}" |
| 64 | dest="{{ ansible_user_dir }}/{{ item }}" |
| 65 | with_items: |
| 66 | - "docker-install-playbook.yml" |
| 67 | - "docker_apt_key.gpg" |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 68 | |
| 69 | - name: Install docker in VM's that require it |
Zack Williams | 9e74c4a | 2016-05-21 10:00:03 -0700 | [diff] [blame] | 70 | command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml" |