blob: 47895f6b2d13ddb91bdf152a7faef3db3a204cab [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
Tony Mackdaeaf652015-12-28 16:25:20 +00005 user: ubuntu
Tony Mack4c3e2ba2015-12-28 15:42:25 +00006 sudo: yes
7 vars:
8 # Each OpenCloud cluster needs a unique mgmt_net_prefix
9 mgmt_net_prefix: 192.168.100
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 sudo: yes
82 tasks:
83 - name: Create VMs to host OpenCloud services
84 sudo: no
85 script: scripts/create-vms.sh
86
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
122- hosts: head
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
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
158 - name: Add all Juju relations between services
159 script: scripts/juju-relations.py
160
161 - name: Wait for relations to be fully added
162 script: scripts/wait-for-services.sh
163
164# Play: Use libvirt hooks to set up iptables
165- hosts: head
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
187- hosts: head
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
202 - name: (CloudLab) Make sure that /root/setup exists
203 file: path=/root/setup state=directory
204 sudo: yes
205 when: cloudlab
206
207 - name: (CloudLab) Copy credentials to /root/setup
208 shell: scp admin-openrc.sh /root/setup
209 sudo: yes
210 when: cloudlab
211
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
221 - name: Run network setup script
222 shell: ansible nova-cloud-controller -m script -u ubuntu -a "/usr/local/src/network-setup.sh"
223
224 - name: Get public key
225 shell: cat {{ ansible_env['PWD'] }}/.ssh/id_rsa.pub
226 register: sshkey
227
228 - name: Copy CA certificate
229 shell: sudo juju scp nova-cloud-controller/0:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
230 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
231
232 - name: Update CA ca-certificates
233 shell: update-ca-certificates
234 sudo: yes
235
236- hosts: compute
237 sudo: yes
238 vars:
239 control_net: "{{ hostvars['head']['ansible_virbr0']['ipv4']['network'] }}/24"
240 gateway: "{{ hostvars['head']['ansible_default_ipv4']['address'] }}"
241 tasks:
242 - name: Install package needed by Juju
243 apt: name=python-yaml state=present
244
245 - name: Add key
246 authorized_key: user="{{ ansible_env['SUDO_USER'] }}"
247 key="{{ hostvars['head']['sshkey']['stdout'] }}"
248
249 - name: Add route via /etc/rc.local
250 template: src=templates/etc/rc.local.cloudlab
251 dest=/etc/rc.local
252 mode=0755
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
262 notify:
263 - run /etc/rc.local
264
265 - name: Touch ~/.ssh/config
266 file: path=/var/lib/nova state=directory
267
268 - name: (CloudLab) Set up extra disk space
269 shell: /usr/testbed/bin/mkextrafs /var/lib/nova
270 creates=/var/lib/nova/lost+found
271 when: cloudlab
272
273 handlers:
274 - name: run /etc/rc.local
275 shell: /etc/rc.local