Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 1 | --- |
| 2 | # Play: set up head node |
| 3 | # Assumes basic /etc/ansible/hosts file |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 4 | - hosts: head |
Tony Mack | daeaf65 | 2015-12-28 16:25:20 +0000 | [diff] [blame^] | 5 | user: ubuntu |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 6 | sudo: yes |
Andy Bavier | 85a52a8 | 2015-10-22 15:18:44 -0400 | [diff] [blame] | 7 | vars: |
| 8 | # Each OpenCloud cluster needs a unique mgmt_net_prefix |
| 9 | mgmt_net_prefix: 192.168.100 |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 10 | tasks: |
| 11 | |
Andy Bavier | 58c8c52 | 2015-09-30 16:24:28 -0400 | [diff] [blame] | 12 | - apt: name={{ item }} update_cache=yes |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 13 | with_items: |
| 14 | - python-pycurl |
| 15 | - software-properties-common |
| 16 | |
| 17 | - name: Add Juju repository |
| 18 | apt_repository: repo="ppa:juju/stable" |
| 19 | |
| 20 | - name: Add Ansible repository |
| 21 | apt_repository: repo="ppa:ansible/ansible" |
| 22 | |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 23 | - name: Update Ansible cache |
| 24 | apt: update_cache=yes |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 25 | |
| 26 | - name: Install packages |
| 27 | apt: name={{ item }} state=latest |
| 28 | with_items: |
| 29 | - ansible |
| 30 | - uvtool |
| 31 | - git |
| 32 | - bzr |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 33 | - juju-core |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 34 | - python-novaclient |
| 35 | - python-neutronclient |
| 36 | - python-keystoneclient |
| 37 | - python-glanceclient |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 38 | |
| 39 | - name: Get juju-ansible git repo |
| 40 | git: repo=https://github.com/cmars/juju-ansible.git |
| 41 | dest=/usr/local/src/juju-ansible |
| 42 | |
| 43 | - name: Set up juju-ansible symlink |
| 44 | file: dest=/usr/local/bin/juju-ansible |
| 45 | src=/usr/local/src/juju-ansible/juju-ansible |
| 46 | state=link |
| 47 | |
| 48 | - name: Set up juju-ansible-playbook symlink |
| 49 | file: dest=/usr/local/bin/juju-ansible-playbook |
| 50 | src=/usr/local/src/juju-ansible/juju-ansible |
| 51 | state=link |
| 52 | |
| 53 | - name: Generate key to use in VMs |
| 54 | user: name={{ ansible_env['SUDO_USER'] }} generate_ssh_key=yes |
| 55 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 56 | - name: (CloudLab) Set up extra disk space |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 57 | shell: /usr/testbed/bin/mkextrafs /var/lib/uvtool/libvirt/images |
| 58 | creates=/var/lib/uvtool/libvirt/images/lost+found |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 59 | when: cloudlab |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 60 | |
| 61 | - name: Add myself to libvirtd group |
Andy Bavier | b1ae26e | 2015-09-17 16:20:46 -0400 | [diff] [blame] | 62 | user: name={{ ansible_env['SUDO_USER'] }} |
| 63 | groups=libvirtd |
| 64 | append=yes |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 65 | |
| 66 | - name: Get trusty image for uvtool |
| 67 | shell: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily release=trusty arch=amd64 |
| 68 | |
Andy Bavier | 85a52a8 | 2015-10-22 15:18:44 -0400 | [diff] [blame] | 69 | - name: Change the virbr0 subnet to {{ mgmt_net_prefix }}.0/24 |
| 70 | template: src=templates/etc/libvirt/qemu/networks/default.xml.j2 |
| 71 | dest=/etc/libvirt/qemu/networks/default.xml |
| 72 | notify: |
| 73 | - recreate default net |
Andy Bavier | c1dfb88 | 2015-10-07 16:20:24 -0400 | [diff] [blame] | 74 | |
Andy Bavier | 85a52a8 | 2015-10-22 15:18:44 -0400 | [diff] [blame] | 75 | handlers: |
| 76 | - name: recreate default net |
Andy Bavier | 2622d4e | 2015-10-23 15:59:08 -0400 | [diff] [blame] | 77 | script: scripts/recreate-virbr0.sh |
Andy Bavier | 85a52a8 | 2015-10-22 15:18:44 -0400 | [diff] [blame] | 78 | |
| 79 | # Play: create VMs to host OpenStack services |
| 80 | - hosts: head |
| 81 | sudo: yes |
| 82 | tasks: |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 83 | - name: Create VMs to host OpenCloud services |
| 84 | sudo: no |
| 85 | script: scripts/create-vms.sh |
| 86 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 87 | - include: tasks/vm-ips.yml |
| 88 | |
| 89 | - name: Add VMs to /etc/hosts |
| 90 | template: src=templates/etc/hosts.j2 |
| 91 | dest=/etc/hosts |
| 92 | notify: |
| 93 | - Reload dnsmasq |
| 94 | |
| 95 | - name: Set up /etc/ansible/hosts |
| 96 | template: src=templates/etc/ansible/hosts.j2 |
| 97 | dest=/etc/ansible/hosts |
| 98 | |
| 99 | - name: Copy ansible.cfg to disable host key checking |
| 100 | sudo: no |
| 101 | copy: src=files/ansible.cfg |
| 102 | dest={{ ansible_env['PWD'] }}/.ansible.cfg |
| 103 | |
| 104 | - name: Touch ~/.ssh/config |
| 105 | sudo: no |
| 106 | file: path={{ ansible_env['PWD'] }}/.ssh/config state=touch |
| 107 | |
| 108 | - name: Disable host key checking in SSH |
| 109 | sudo: no |
| 110 | lineinfile: dest={{ ansible_env['PWD'] }}/.ssh/config |
| 111 | line="StrictHostKeyChecking no" |
| 112 | |
| 113 | - name: Test that we can log into every VM |
| 114 | sudo: no |
| 115 | shell: ansible services -m ping -u ubuntu |
| 116 | |
| 117 | handlers: |
| 118 | - name: Reload dnsmasq |
| 119 | shell: killall -HUP dnsmasq |
| 120 | |
| 121 | # Play: Install services using Juju |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 122 | - hosts: head |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 123 | vars: |
| 124 | charm_src: /usr/local/src/charms/trusty |
| 125 | tasks: |
| 126 | - name: Initialize Juju |
| 127 | sudo: no |
| 128 | shell: juju generate-config |
| 129 | creates={{ ansible_env['PWD'] }}/.juju/environments.yaml |
| 130 | |
| 131 | - shell: uvt-kvm ip juju |
| 132 | register: juju_ip |
| 133 | |
| 134 | - name: Juju config file |
| 135 | sudo: no |
| 136 | template: src=templates/environments.yaml.j2 |
| 137 | dest={{ ansible_env['PWD'] }}/.juju/environments.yaml |
| 138 | |
| 139 | - name: Bootstrap Juju |
| 140 | sudo: no |
| 141 | shell: juju bootstrap |
| 142 | creates={{ ansible_env['PWD'] }}/.juju/environments/manual.jenv |
| 143 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 144 | - name: Copy openstack.cfg for Juju |
| 145 | sudo: yes |
| 146 | copy: src=files/openstack.cfg |
| 147 | dest=/usr/local/src/openstack.cfg |
| 148 | |
| 149 | - name: Check for /usr/local/src/charms/trusty |
| 150 | sudo: yes |
| 151 | file: path={{ charm_src }} |
| 152 | state=directory |
| 153 | mode=0755 |
| 154 | |
| 155 | - name: Deploy OpenStack services with Juju |
| 156 | script: scripts/juju-setup.py |
| 157 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 158 | - name: Add all Juju relations between services |
| 159 | script: scripts/juju-relations.py |
| 160 | |
Andy Bavier | 5201714 | 2015-10-05 15:01:36 -0400 | [diff] [blame] | 161 | - name: Wait for relations to be fully added |
| 162 | script: scripts/wait-for-services.sh |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 163 | |
| 164 | # Play: Use libvirt hooks to set up iptables |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 165 | - hosts: head |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 166 | sudo: yes |
| 167 | tasks: |
| 168 | - name: Enable port forwarding for services |
| 169 | copy: src=files/{{ item }} |
| 170 | dest={{ item }} |
| 171 | mode=0755 |
| 172 | notify: |
| 173 | - reload libvirt config |
| 174 | - run qemu hook |
| 175 | with_items: |
| 176 | - /etc/libvirt/hooks/daemon |
| 177 | - /etc/libvirt/hooks/qemu |
| 178 | |
| 179 | handlers: |
| 180 | - name: reload libvirt config |
| 181 | shell: killall -HUP libvirtd |
| 182 | |
| 183 | - name: run qemu hook |
| 184 | shell: /etc/libvirt/hooks/qemu start start |
| 185 | |
| 186 | # Play: Create credentials, set up some basic OpenStack |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 187 | - hosts: head |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 188 | sudo: no |
| 189 | tasks: |
| 190 | |
| 191 | - name: Get keystone admin password |
| 192 | shell: juju run --unit=keystone/0 "sudo cat /var/lib/keystone/keystone.passwd" |
| 193 | register: keystone_password |
| 194 | |
| 195 | - shell: uvt-kvm ip keystone |
| 196 | register: keystone_ip |
| 197 | |
| 198 | - name: Create credentials |
| 199 | template: src=templates/admin-openrc.sh.j2 |
| 200 | dest={{ ansible_env['PWD'] }}/admin-openrc.sh |
| 201 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 202 | - name: (CloudLab) Make sure that /root/setup exists |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 203 | file: path=/root/setup state=directory |
| 204 | sudo: yes |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 205 | when: cloudlab |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 206 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 207 | - name: (CloudLab) Copy credentials to /root/setup |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 208 | shell: scp admin-openrc.sh /root/setup |
| 209 | sudo: yes |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 210 | when: cloudlab |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 211 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 212 | - name: Copy credentials to nova-cloud-controller |
| 213 | shell: "scp admin-openrc.sh ubuntu@nova-cloud-controller:" |
| 214 | |
| 215 | - name: Copy network setup script |
| 216 | sudo: yes |
| 217 | copy: src=scripts/network-setup.sh |
| 218 | dest=/usr/local/src/network-setup.sh |
| 219 | mode=0644 |
| 220 | |
Andy Bavier | 4e7762e | 2015-08-27 14:36:34 -0400 | [diff] [blame] | 221 | - name: Run network setup script |
| 222 | shell: ansible nova-cloud-controller -m script -u ubuntu -a "/usr/local/src/network-setup.sh" |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 223 | |
| 224 | - name: Get public key |
| 225 | shell: cat {{ ansible_env['PWD'] }}/.ssh/id_rsa.pub |
| 226 | register: sshkey |
| 227 | |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 228 | - name: Copy CA certificate |
Andy Bavier | 5201714 | 2015-10-05 15:01:36 -0400 | [diff] [blame] | 229 | shell: sudo juju scp nova-cloud-controller/0:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 230 | creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 231 | |
| 232 | - name: Update CA ca-certificates |
| 233 | shell: update-ca-certificates |
| 234 | sudo: yes |
| 235 | |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 236 | - hosts: compute |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 237 | sudo: yes |
| 238 | vars: |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 239 | control_net: "{{ hostvars['head']['ansible_virbr0']['ipv4']['network'] }}/24" |
| 240 | gateway: "{{ hostvars['head']['ansible_default_ipv4']['address'] }}" |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 241 | tasks: |
| 242 | - name: Install package needed by Juju |
| 243 | apt: name=python-yaml state=present |
| 244 | |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 245 | - name: Add key |
| 246 | authorized_key: user="{{ ansible_env['SUDO_USER'] }}" |
Andy Bavier | 1704c58 | 2015-10-22 14:02:25 -0400 | [diff] [blame] | 247 | key="{{ hostvars['head']['sshkey']['stdout'] }}" |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 248 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 249 | - name: Add route via /etc/rc.local |
| 250 | template: src=templates/etc/rc.local.cloudlab |
| 251 | dest=/etc/rc.local |
| 252 | mode=0755 |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 253 | when: cloudlab |
| 254 | notify: |
| 255 | - run /etc/rc.local |
| 256 | |
| 257 | - name: Add route via /etc/rc.local |
| 258 | template: src=templates/etc/rc.local |
| 259 | dest=/etc/rc.local |
| 260 | mode=0755 |
| 261 | when: not cloudlab |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 262 | notify: |
| 263 | - run /etc/rc.local |
| 264 | |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 265 | - name: Touch ~/.ssh/config |
| 266 | file: path=/var/lib/nova state=directory |
| 267 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 268 | - name: (CloudLab) Set up extra disk space |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 269 | shell: /usr/testbed/bin/mkextrafs /var/lib/nova |
| 270 | creates=/var/lib/nova/lost+found |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 271 | when: cloudlab |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 272 | |
| 273 | handlers: |
| 274 | - name: run /etc/rc.local |
| 275 | shell: /etc/rc.local |