blob: 725d6793cb2322116faa128d96e7fa9c01c90d71 [file] [log] [blame]
Andy Bavier8d51c6c2015-04-01 11:40:22 -04001---
2# Play: set up head node
3# Assumes basic /etc/ansible/hosts file
Tony Mack992a63b2016-02-23 22:05:56 +00004- hosts: head
5 user: ubuntu
Andy Bavier8d51c6c2015-04-01 11:40:22 -04006 sudo: yes
Tony Mack992a63b2016-02-23 22:05:56 +00007 vars:
8 # Each OpenCloud cluster needs a unique mgmt_net_prefix
9 mgmt_net_prefix: 192.168.103
Andy Bavier8d51c6c2015-04-01 11:40:22 -040010 tasks:
11
Tony Mack992a63b2016-02-23 22:05:56 +000012 - apt: name={{ item }} update_cache=yes
13 with_items:
14 - python-pycurl
15 - software-properties-common
Andy Bavier8d51c6c2015-04-01 11:40:22 -040016
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
Tony Mack992a63b2016-02-23 22:05:56 +000023 - name: Update Ansible cache
24 apt: update_cache=yes
Andy Bavier8d51c6c2015-04-01 11:40:22 -040025
26 - name: Install packages
Andy Bavierdd0b30a2015-04-01 12:15:31 -040027 apt: name={{ item }} state=latest
Andy Bavier8d51c6c2015-04-01 11:40:22 -040028 with_items:
Andy Bavierdd0b30a2015-04-01 12:15:31 -040029 - ansible
30 - uvtool
31 - git
Tony Mack992a63b2016-02-23 22:05:56 +000032 - bzr
33 - juju-core
34 - python-novaclient
35 - python-neutronclient
36 - python-keystoneclient
37 - python-glanceclient
Andy Bavier8d51c6c2015-04-01 11:40:22 -040038
39 - name: Get juju-ansible git repo
40 git: repo=https://github.com/cmars/juju-ansible.git
Andy Bavier1416aad2015-04-13 14:55:54 -040041 dest=/usr/local/src/juju-ansible
Andy Bavier8d51c6c2015-04-01 11:40:22 -040042
43 - name: Set up juju-ansible symlink
44 file: dest=/usr/local/bin/juju-ansible
Andy Bavier1416aad2015-04-13 14:55:54 -040045 src=/usr/local/src/juju-ansible/juju-ansible
Andy Bavier8d51c6c2015-04-01 11:40:22 -040046 state=link
47
48 - name: Set up juju-ansible-playbook symlink
49 file: dest=/usr/local/bin/juju-ansible-playbook
Andy Bavier1416aad2015-04-13 14:55:54 -040050 src=/usr/local/src/juju-ansible/juju-ansible
Andy Bavier8d51c6c2015-04-01 11:40:22 -040051 state=link
52
53 - name: Generate key to use in VMs
Tony Mack992a63b2016-02-23 22:05:56 +000054 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -040065
Andy Bavier8d51c6c2015-04-01 11:40:22 -040066 - name: Get trusty image for uvtool
Tony Mack992a63b2016-02-23 22:05:56 +000067 shell: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily release=trusty arch=amd64
Andy Bavier8d51c6c2015-04-01 11:40:22 -040068
Tony Mack992a63b2016-02-23 22:05:56 +000069 - 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:
Andy Bavier8d51c6c2015-04-01 11:40:22 -040084 - name: Create VMs to host OpenCloud services
85 sudo: no
86 script: scripts/create-vms.sh
87
Andy Bavier8d51c6c2015-04-01 11:40:22 -040088 - include: tasks/vm-ips.yml
89
90 - name: Add VMs to /etc/hosts
91 template: src=templates/etc/hosts.j2
92 dest=/etc/hosts
Andy Bavier1416aad2015-04-13 14:55:54 -040093 notify:
94 - Reload dnsmasq
Andy Bavier8d51c6c2015-04-01 11:40:22 -040095
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
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400103 dest={{ ansible_env['PWD'] }}/.ansible.cfg
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400104
105 - name: Touch ~/.ssh/config
106 sudo: no
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400107 file: path={{ ansible_env['PWD'] }}/.ssh/config state=touch
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400108
109 - name: Disable host key checking in SSH
110 sudo: no
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400111 lineinfile: dest={{ ansible_env['PWD'] }}/.ssh/config
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400112 line="StrictHostKeyChecking no"
113
114 - name: Test that we can log into every VM
115 sudo: no
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400116 shell: ansible services -m ping -u ubuntu
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400117
Andy Bavier1416aad2015-04-13 14:55:54 -0400118 handlers:
119 - name: Reload dnsmasq
120 shell: killall -HUP dnsmasq
121
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400122# Play: Install services using Juju
Tony Mack992a63b2016-02-23 22:05:56 +0000123- hosts: head
124 user: ubuntu
125 vars:
126 charm_src: /usr/local/src/charms/trusty
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400127 tasks:
128 - name: Initialize Juju
129 sudo: no
130 shell: juju generate-config
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400131 creates={{ ansible_env['PWD'] }}/.juju/environments.yaml
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400132
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
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400139 dest={{ ansible_env['PWD'] }}/.juju/environments.yaml
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400140
141 - name: Bootstrap Juju
142 sudo: no
143 shell: juju bootstrap
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400144 creates={{ ansible_env['PWD'] }}/.juju/environments/manual.jenv
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400145
Tony Mack992a63b2016-02-23 22:05:56 +0000146 - name: Copy openstack.cfg for Juju
Andy Bavier1416aad2015-04-13 14:55:54 -0400147 sudo: yes
Tony Mack992a63b2016-02-23 22:05:56 +0000148 copy: src=files/openstack.cfg
Andy Bavier1416aad2015-04-13 14:55:54 -0400149 dest=/usr/local/src/openstack.cfg
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400150
Tony Mack992a63b2016-02-23 22:05:56 +0000151 - name: Check for /usr/local/src/charms/trusty
152 sudo: yes
153 file: path={{ charm_src }}
154 state=directory
155 mode=0755
156
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400157 - name: Deploy OpenStack services with Juju
158 script: scripts/juju-setup.py
159
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400160 - name: Add all Juju relations between services
161 script: scripts/juju-relations.py
162
Tony Mack992a63b2016-02-23 22:05:56 +0000163 - name: Wait for relations to be fully added
164 script: scripts/wait-for-services.sh
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400165
166# Play: Use libvirt hooks to set up iptables
Tony Mack992a63b2016-02-23 22:05:56 +0000167- hosts: head
168 user: ubuntu
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400169 sudo: yes
170 tasks:
171 - name: Enable port forwarding for services
172 copy: src=files/{{ item }}
173 dest={{ item }}
174 mode=0755
Tony Mack992a63b2016-02-23 22:05:56 +0000175 notify:
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400176 - 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
Tony Mack992a63b2016-02-23 22:05:56 +0000189# Play: Create credentials, set up some basic OpenStack
190- hosts: head
191 user: ubuntu
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400192 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
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400204 dest={{ ansible_env['PWD'] }}/admin-openrc.sh
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400205
Tony Mack992a63b2016-02-23 22:05:56 +0000206 - 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400216 - name: Copy credentials to nova-cloud-controller
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400217 shell: "scp admin-openrc.sh ubuntu@nova-cloud-controller:"
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400218
Andy Bavier1416aad2015-04-13 14:55:54 -0400219 - 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400228 - name: Get public key
Andy Bavierdd0b30a2015-04-01 12:15:31 -0400229 shell: cat {{ ansible_env['PWD'] }}/.ssh/id_rsa.pub
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400230 register: sshkey
231
Tony Mack992a63b2016-02-23 22:05:56 +0000232 - 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400242 sudo: yes
Tony Mack992a63b2016-02-23 22:05:56 +0000243 vars:
244 control_net: "{{ hostvars['head']['ansible_virbr0']['ipv4']['network'] }}/24"
245 gateway: "{{ hostvars['head']['ansible_default_ipv4']['address'] }}"
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400246 tasks:
Andy Bavier1416aad2015-04-13 14:55:54 -0400247 - name: Install package needed by Juju
248 apt: name=python-yaml state=present
249
Tony Mack992a63b2016-02-23 22:05:56 +0000250 - 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400262 - name: Add route via /etc/rc.local
263 template: src=templates/etc/rc.local
264 dest=/etc/rc.local
265 mode=0755
Tony Mack992a63b2016-02-23 22:05:56 +0000266 when: not cloudlab
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400267 notify:
268 - run /etc/rc.local
269
Tony Mack992a63b2016-02-23 22:05:56 +0000270 - 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
Andy Bavier8d51c6c2015-04-01 11:40:22 -0400277
278 handlers:
279 - name: run /etc/rc.local
280 shell: /etc/rc.local