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