Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 1 | --- |
| 2 | # file: create-vms/tasks/main.yml |
David K. Bainbridge | 77a516a | 2016-10-27 10:57:57 -0700 | [diff] [blame] | 3 | - name: Ensure DIG |
| 4 | become: yes |
| 5 | apt: |
| 6 | name: dnsutils=1:9* |
| 7 | state: present |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 8 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 9 | - name: create Virtual Machines with uvt-kvm |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 10 | command: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \ |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 11 | --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr" |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 12 | args: |
| 13 | creates: "/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 14 | with_items: "{{ head_vm_list }}" |
| 15 | |
| 16 | - name: Have VMs autostart on reboot |
| 17 | become: yes |
| 18 | virt: |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 19 | name: "{{ item.name }}" |
| 20 | command: autostart |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 21 | with_items: "{{ head_vm_list }}" |
| 22 | |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 23 | - name: fetch IP of DHCP harvester |
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 | command: docker-ip harvester |
| 26 | register: harvester_ip |
| 27 | changed_when: False |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 28 | |
| 29 | - name: force a harvest to get 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 | uri: |
| 32 | url: http://{{ harvester_ip.stdout }}:8954/harvest |
| 33 | method: POST |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 34 | |
| 35 | - name: wait for VM name resolution |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 36 | when: on_maas |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 37 | host_dns_check: |
Andy Bavier | 6df0468 | 2016-09-30 06:09:36 -0400 | [diff] [blame] | 38 | hosts: "{{ head_vm_list | map(attribute='name') | list | to_json }}" |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 39 | command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest" |
| 40 | register: all_resolved |
| 41 | until: all_resolved.everyone == "OK" |
| 42 | retries: 5 |
| 43 | delay: 10 |
| 44 | failed_when: all_resolved.everyone != "OK" |
David K. Bainbridge | d3da608 | 2016-08-11 14:01:27 -0700 | [diff] [blame] | 45 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 46 | - name: wait for VM's to come up |
| 47 | wait_for: |
| 48 | host={{ item.name }} |
| 49 | port=22 |
| 50 | with_items: "{{ head_vm_list }}" |
| 51 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 52 | - name: Verify that we can log into every VM |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 53 | command: ansible vms -m ping -u ubuntu |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 54 | tags: |
| 55 | - skip_ansible_lint # connectivity check |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 56 | |
| 57 | - name: Have VM's use the apt-cache |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 58 | command: ansible vms -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 Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 59 | tags: |
| 60 | - skip_ansible_lint # running a sub job |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 61 | |
Andy Bavier | 42eeab6 | 2016-07-01 16:48:57 -0400 | [diff] [blame] | 62 | - name: Update apt cache |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 63 | command: ansible vms -m apt -b -u ubuntu -a "update_cache=yes cache_valid_time=3600" |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 64 | tags: |
| 65 | - skip_ansible_lint # running a sub job |
Zack Williams | 6f5a6e7 | 2016-08-10 17:45:27 -0700 | [diff] [blame] | 66 | |
| 67 | - name: Update software in all the VMs |
| 68 | when: run_dist_upgrade |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 69 | command: ansible vms -m apt -b -u ubuntu -a "upgrade=dist" |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 70 | tags: |
| 71 | - skip_ansible_lint # running a sub job |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 72 | |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 73 | - 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] | 74 | when: not on_maas |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 75 | template: |
| 76 | src=eth0.cfg.j2 |
| 77 | dest={{ ansible_user_dir }}/eth0.cfg |
| 78 | |
| 79 | - name: Copy eth0 interface config file to all VMs |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 80 | when: not on_maas |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 81 | command: ansible vms -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] | 82 | |
| 83 | - name: Restart eth0 interface on all VMs |
Andy Bavier | 0481a8a | 2016-07-14 13:01:45 +0200 | [diff] [blame] | 84 | when: not on_maas |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 85 | command: ansible vms -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0" |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 86 | |
| 87 | - 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] | 88 | when: not on_maas |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 89 | command: ansible vms -m ping -u ubuntu |
Zack Williams | d31bbc9 | 2016-05-20 11:43:18 -0700 | [diff] [blame] | 90 | |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 91 | # sshkey is registered in head-prep task |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 92 | - name: Enable root ssh login on VM's that require it |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 93 | command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'" |
| 94 | with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}" |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 95 | tags: |
| 96 | - skip_ansible_lint # FIXME, ssh key mangling |
Zack Williams | 2cffa0f | 2016-05-20 12:18:47 -0700 | [diff] [blame] | 97 | |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 98 | - name: Copy over docker installation playbook and docker apt-key |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 99 | copy: |
Zack Williams | 7d6747d | 2016-06-20 10:38:59 -0700 | [diff] [blame] | 100 | src="{{ item }}" |
| 101 | dest="{{ ansible_user_dir }}/{{ item }}" |
| 102 | with_items: |
| 103 | - "docker-install-playbook.yml" |
| 104 | - "docker_apt_key.gpg" |
Zack Williams | e4fbacc | 2016-05-21 07:18:43 -0700 | [diff] [blame] | 105 | |
| 106 | - name: Install docker in VM's that require it |
Zack Williams | 9e74c4a | 2016-05-21 10:00:03 -0700 | [diff] [blame] | 107 | command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml" |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 108 | tags: |
| 109 | - skip_ansible_lint # running a sub job |
Zack Williams | 682450e | 2016-11-19 09:04:41 -0700 | [diff] [blame] | 110 | |