blob: 323c4a0d9dffde8351acbd005890964978285453 [file] [log] [blame]
Zack Williamsd31bbc92016-05-20 11:43:18 -07001---
2# file: create-vms/tasks/main.yml
David K. Bainbridge77a516a2016-10-27 10:57:57 -07003- name: Ensure DIG
4 become: yes
5 apt:
6 name: dnsutils=1:9*
7 state: present
Zack Williamsd31bbc92016-05-20 11:43:18 -07008
Zack Williamsd31bbc92016-05-20 11:43:18 -07009- name: create Virtual Machines with uvt-kvm
Zack Williams35624562016-08-28 17:12:26 -070010 command: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \
Zack Williamsd31bbc92016-05-20 11:43:18 -070011 --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr"
Zack Williams35624562016-08-28 17:12:26 -070012 args:
13 creates: "/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow"
Zack Williamsd31bbc92016-05-20 11:43:18 -070014 with_items: "{{ head_vm_list }}"
15
16- name: Have VMs autostart on reboot
17 become: yes
18 virt:
Zack Williams6f5a6e72016-08-10 17:45:27 -070019 name: "{{ item.name }}"
20 command: autostart
Zack Williamsd31bbc92016-05-20 11:43:18 -070021 with_items: "{{ head_vm_list }}"
22
David K. Bainbridged3da6082016-08-11 14:01:27 -070023- name: fetch IP of DHCP harvester
Zack Williams6f5a6e72016-08-10 17:45:27 -070024 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070025 command: docker-ip harvester
26 register: harvester_ip
27 changed_when: False
David K. Bainbridged3da6082016-08-11 14:01:27 -070028
29- name: force a harvest to get VM name resolution
Zack Williams6f5a6e72016-08-10 17:45:27 -070030 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070031 uri:
32 url: http://{{ harvester_ip.stdout }}:8954/harvest
33 method: POST
David K. Bainbridged3da6082016-08-11 14:01:27 -070034
35- name: wait for VM name resolution
Zack Williams6f5a6e72016-08-10 17:45:27 -070036 when: on_maas
David K. Bainbridged3da6082016-08-11 14:01:27 -070037 host_dns_check:
Andy Bavier6df04682016-09-30 06:09:36 -040038 hosts: "{{ head_vm_list | map(attribute='name') | list | to_json }}"
David K. Bainbridged3da6082016-08-11 14:01:27 -070039 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. Bainbridged3da6082016-08-11 14:01:27 -070045
Zack Williamsd31bbc92016-05-20 11:43:18 -070046- 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
52- name: Create /etc/ansible/hosts file
53 become: yes
54 template:
55 src=ansible_hosts.j2
56 dest=/etc/ansible/hosts
57
58- name: Verify that we can log into every VM
59 command: ansible services -m ping -u ubuntu
Zack Williams35624562016-08-28 17:12:26 -070060 tags:
61 - skip_ansible_lint # connectivity check
Zack Williamsd31bbc92016-05-20 11:43:18 -070062
63- name: Have VM's use the apt-cache
64 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 -070065 tags:
66 - skip_ansible_lint # running a sub job
Zack Williamsd31bbc92016-05-20 11:43:18 -070067
Andy Bavier42eeab62016-07-01 16:48:57 -040068- name: Update apt cache
Zack Williams6f5a6e72016-08-10 17:45:27 -070069 command: ansible services -m apt -b -u ubuntu -a "update_cache=yes cache_valid_time=3600"
Zack Williams35624562016-08-28 17:12:26 -070070 tags:
71 - skip_ansible_lint # running a sub job
Zack Williams6f5a6e72016-08-10 17:45:27 -070072
73- name: Update software in all the VMs
74 when: run_dist_upgrade
75 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist"
Zack Williams35624562016-08-28 17:12:26 -070076 tags:
77 - skip_ansible_lint # running a sub job
Zack Williamsa3e40562016-07-05 12:05:39 -070078
Zack Williamsd31bbc92016-05-20 11:43:18 -070079- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams6f5a6e72016-08-10 17:45:27 -070080 when: not on_maas
Zack Williamsd31bbc92016-05-20 11:43:18 -070081 template:
82 src=eth0.cfg.j2
83 dest={{ ansible_user_dir }}/eth0.cfg
84
85- name: Copy eth0 interface config file to all VMs
Andy Bavier0481a8a2016-07-14 13:01:45 +020086 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070087 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 -070088
89- name: Restart eth0 interface on all VMs
Andy Bavier0481a8a2016-07-14 13:01:45 +020090 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070091 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williamsd31bbc92016-05-20 11:43:18 -070092
93- name: Verify that we can log into every VM after restarting network interfaces
Andy Bavier0481a8a2016-07-14 13:01:45 +020094 when: not on_maas
Zack Williams6f5a6e72016-08-10 17:45:27 -070095 command: ansible services -m ping -u ubuntu
Zack Williamsd31bbc92016-05-20 11:43:18 -070096
Zack Williams2cffa0f2016-05-20 12:18:47 -070097# sshkey is registered in head-prep task
Zack Williamse4fbacc2016-05-21 07:18:43 -070098- name: Enable root ssh login on VM's that require it
Zack Williams2cffa0f2016-05-20 12:18:47 -070099 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
100 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
Zack Williams35624562016-08-28 17:12:26 -0700101 tags:
102 - skip_ansible_lint # FIXME, ssh key mangling
Zack Williams2cffa0f2016-05-20 12:18:47 -0700103
Zack Williams7d6747d2016-06-20 10:38:59 -0700104- name: Copy over docker installation playbook and docker apt-key
Zack Williamse4fbacc2016-05-21 07:18:43 -0700105 copy:
Zack Williams7d6747d2016-06-20 10:38:59 -0700106 src="{{ item }}"
107 dest="{{ ansible_user_dir }}/{{ item }}"
108 with_items:
109 - "docker-install-playbook.yml"
110 - "docker_apt_key.gpg"
Zack Williamse4fbacc2016-05-21 07:18:43 -0700111
112- name: Install docker in VM's that require it
Zack Williams9e74c4a2016-05-21 10:00:03 -0700113 command: ansible-playbook "{{ ansible_user_dir }}/docker-install-playbook.yml"
Zack Williams35624562016-08-28 17:12:26 -0700114 tags:
115 - skip_ansible_lint # running a sub job
116
Zack Williams6f5a6e72016-08-10 17:45:27 -0700117