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 |
Tony Mack | df55286 | 2015-12-28 20:06:43 +0000 | [diff] [blame] | 81 | user: ubuntu |
Andy Bavier | 85a52a8 | 2015-10-22 15:18:44 -0400 | [diff] [blame] | 82 | sudo: yes |
| 83 | tasks: |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 84 | - name: Create VMs to host OpenCloud services |
| 85 | sudo: no |
| 86 | script: scripts/create-vms.sh |
| 87 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 123 | - hosts: head |
Tony Mack | df55286 | 2015-12-28 20:06:43 +0000 | [diff] [blame] | 124 | user: ubuntu |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 160 | - name: Add all Juju relations between services |
| 161 | script: scripts/juju-relations.py |
| 162 | |
Andy Bavier | 5201714 | 2015-10-05 15:01:36 -0400 | [diff] [blame] | 163 | - name: Wait for relations to be fully added |
| 164 | script: scripts/wait-for-services.sh |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 165 | |
| 166 | # Play: Use libvirt hooks to set up iptables |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 167 | - hosts: head |
Tony Mack | df55286 | 2015-12-28 20:06:43 +0000 | [diff] [blame] | 168 | user: ubuntu |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 190 | - hosts: head |
Tony Mack | df55286 | 2015-12-28 20:06:43 +0000 | [diff] [blame] | 191 | user: ubuntu |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 206 | - name: (CloudLab) Make sure that /root/setup exists |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 207 | file: path=/root/setup state=directory |
| 208 | sudo: yes |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 209 | when: cloudlab |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 210 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 211 | - name: (CloudLab) Copy credentials to /root/setup |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 212 | shell: scp admin-openrc.sh /root/setup |
| 213 | sudo: yes |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 214 | when: cloudlab |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 215 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 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 | |
Andy Bavier | 4e7762e | 2015-08-27 14:36:34 -0400 | [diff] [blame] | 225 | - name: Run network setup script |
| 226 | 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] | 227 | |
| 228 | - name: Get public key |
| 229 | shell: cat {{ ansible_env['PWD'] }}/.ssh/id_rsa.pub |
| 230 | register: sshkey |
| 231 | |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 232 | - name: Copy CA certificate |
Andy Bavier | 5201714 | 2015-10-05 15:01:36 -0400 | [diff] [blame] | 233 | 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] | 234 | creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt |
Andy Bavier | 8da6df1 | 2015-10-02 12:33:48 -0400 | [diff] [blame] | 235 | |
| 236 | - name: Update CA ca-certificates |
| 237 | shell: update-ca-certificates |
| 238 | sudo: yes |
| 239 | |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 240 | - hosts: compute |
Tony Mack | df55286 | 2015-12-28 20:06:43 +0000 | [diff] [blame] | 241 | user: ubuntu |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 242 | sudo: yes |
| 243 | vars: |
Andy Bavier | 2255230 | 2015-10-22 12:44:40 -0400 | [diff] [blame] | 244 | control_net: "{{ hostvars['head']['ansible_virbr0']['ipv4']['network'] }}/24" |
| 245 | gateway: "{{ hostvars['head']['ansible_default_ipv4']['address'] }}" |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 246 | tasks: |
| 247 | - name: Install package needed by Juju |
| 248 | apt: name=python-yaml state=present |
| 249 | |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 250 | - name: Add key |
| 251 | authorized_key: user="{{ ansible_env['SUDO_USER'] }}" |
Andy Bavier | 1704c58 | 2015-10-22 14:02:25 -0400 | [diff] [blame] | 252 | key="{{ hostvars['head']['sshkey']['stdout'] }}" |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 253 | |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 254 | - name: Add route via /etc/rc.local |
| 255 | template: src=templates/etc/rc.local.cloudlab |
| 256 | dest=/etc/rc.local |
| 257 | mode=0755 |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 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 |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 267 | notify: |
| 268 | - run /etc/rc.local |
| 269 | |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 270 | - name: Touch ~/.ssh/config |
| 271 | file: path=/var/lib/nova state=directory |
| 272 | |
Andy Bavier | a08061a | 2015-10-05 08:24:59 -0400 | [diff] [blame] | 273 | - name: (CloudLab) Set up extra disk space |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 274 | shell: /usr/testbed/bin/mkextrafs /var/lib/nova |
| 275 | creates=/var/lib/nova/lost+found |
Andy Bavier | 963ec77 | 2015-10-22 19:39:21 -0400 | [diff] [blame] | 276 | when: cloudlab |
Andy Bavier | cccf27b | 2015-08-17 14:48:29 -0400 | [diff] [blame] | 277 | |
| 278 | handlers: |
| 279 | - name: run /etc/rc.local |
| 280 | shell: /etc/rc.local |