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