forked from rstarmer/openstack-kolla-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkolla.yml
248 lines (237 loc) · 9.77 KB
/
kolla.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
---
# Copyright 2016 Kumulus Technologies <[email protected]>
# Copyright 2016 Robert Starmer <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- hosts: build
gather_facts: false
become: true
become_user: root
tasks:
- raw: apt-get install python -y
ignore_errors: true
- hosts: build
become: true
become_user: root
vars:
vld: /var/lib/docker
# domain: opsits.com # added to inventory for less editing
admin_password: openstack
index: 1
# nat_int: enp0s3 # added to inventory
# pub_int: enp0s8
# ext_int: enp0s9
br_int: br0
build_type: source
build_tag: 3.0.0
wait_until_retries: 100
pre_tasks:
- name: fix NAT interface boot
lineinfile: dest=/etc/sysconfig/network-scripts/ifcfg-{{nat_int}} regexp='^ONBOOT.*' line='ONBOOT=yes'
when: ansible_os_family == "RedHat"
- name: upload bridge template
template: dest=/etc/sysconfig/network-scripts/ifcfg-{{ext_int}} src=./bridge.j2
when: ansible_os_family == "RedHat"
- name: upload pulbic template
template: dest=/etc/sysconfig/network-scripts/ifcfg-{{pub_int}} src=./public.j2
when: ansible_os_family == "RedHat"
- name: ensure interfaces are online
command: ifup {{item}}
with_items:
- "{{nat_int}}"
- "{{pub_int}}"
- "{{ext_int}}"
when: ansible_os_family == "RedHat"
- name: install system specific packages
include: debian.yml
when: ansible_os_family == "Debian"
- name: install RedHat specific packages
include: redhat.yml
when: ansible_os_family == "RedHat"
tasks:
- name: add ssh public key
authorized_key: user=root key="{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
- name: update ssh config
copy: src=ssh_config dest=/root/.ssh/config mode=0644
- name: install docker from upstream
shell: curl -sSL https://get.docker.io | bash creates=/etc/docker/key.json
- name: ensure docker is running
service: name=docker state=started enabled=true
- name: Install pip based docker-py module
pip: name=docker-py
- name: check for veth interface
command: ip -d link
register: veth_info
ignore_errors: true
- name: create veth interface
command: ip link add veth0 type veth peer name veth1
when: not (veth_info.stdout | search('veth0'))
- name: add '{{br_int}}'
command: brctl addbr '{{br_int}}'
when: not (veth_info.stdout | search('veth0'))
- name: add veth1 to '{{br_int}}'
command: brctl addif '{{br_int}}' veth1
when: not (veth_info.stdout | search('veth0'))
- name: bring up links
command: ip link set "{{item}}" up
with_items:
- "{{pub_int}}"
- "{{ext_int}}"
- veth0
- veth1
- "{{br_int}}"
- name: get latest pip
pip: name=pip state=latest
- name: Install ansible version 1.9.4 with stable/mitaka kolla branch
pip: name=ansible state=present version=1.9.4
- name: clone kolla
git: repo=https://git.openstack.org/openstack/kolla dest=/root/kolla version=stable/mitaka
ignore_errors: true
- name: install kolla elements
pip: name=kolla/ chdir=/root
- name: update the /etc/kolla directory
command: cp -r etc/kolla /etc
args:
chdir: /root/kolla
creates: /etc/kolla
- name: restart docker
service: name=docker state=restarted
- name: create systemd docker service directory
file: dest=/etc/systemd/system/docker.service.d state=directory
- name: create docker service conf file
copy: src=./kolla.conf dest=/etc/systemd/system/docker.service.d/kolla.conf
- name: restart daemons
command: systemctl daemon-reload
- name: restart docker service
service: name=docker state=restarted
## Update the /etc/kolla/globals.yml based on the environment
- name: ensure base is ubuntu
lineinfile: 'dest=/etc/kolla/globals.yml regexp=^.*kolla_base_distro.* line="kolla_base_distro: ubuntu"'
when: ansible_os_family == "Debian"
- name: ensure install type is source
lineinfile: 'dest=/etc/kolla/globals.yml regexp=^.*kolla_install_type.* line="kolla_install_type: {{build_type}}"'
- name: set tag to {{build_tag}}
lineinfile: 'dest=/etc/kolla/globals.yml regexp=^.*openstack_release.* line="openstack_release: {{build_tag}}"'
# - set_fact:
# vip_net: "{{hostvars[inventory_hostname]['ansible_'+pub_int]['ipv4']['network']}}/{{hostvars[inventory_hostname]['ansible_'+pub_int]['ipv4']['netmask']}}"
# - set_fact:
# vip_ip: "{{vip_net|ipaddr('net')|ipaddr('-2')|ipaddr('address')}}"
- name: set the default internal VIP address
lineinfile: "dest=/etc/kolla/globals.yml regexp=^kolla_internal_vip_address.* line='kolla_internal_vip_address: {{hostvars[inventory_hostname]['ansible_'+pub_int]['ipv4']['address']}}'"
- name: set the docker network interface
lineinfile: "dest=/etc/kolla/globals.yml regexp=^.*network_interface:.* line='network_interface: {{pub_int}}'"
- name: set the docker network interface
lineinfile: "dest=/etc/kolla/globals.yml regexp=^.*neutron_external_interface:.* line='neutron_external_interface: veth0'"
- name: set the docker network interface
lineinfile: "dest=/etc/kolla/globals.yml regexp=^.*neutron_plugin_agent:.* line='neutron_plugin_agent: linuxbridge'"
- name: bypass the haproxy and keepalived config
lineinfile: "dest=/etc/kolla/globals.yml regexp=^.*enable_haproxy:.* line='enable_haproxy: no'"
## Ensure DNS is configured
- name: update resolv.conf with domain
lineinfile: dest=/etc/resolv.conf backrefs=yes regexp=^search(.*) line='search \1 {{domain}}'
- name: ensure hosts file is properly set
lineinfile: dest=/etc/hosts regexp='.*{{inventory_hostname}}.*' line='{{hostvars[inventory_hostname]['ansible_'+pub_int]['ipv4']['address']}} {{inventory_hostname}}.{{domain}} {{inventory_hostname}}'
- name: ensure hostname is set in hostname file
template: dest=/etc/hostname src=./hostname.j2
- name: ensure hostname is properly set
command: hostname {{inventory_hostname}}
## create and upload an SSH pair
- name: ensure ssh directory exists
file: path=~/.ssh state=directory mode=0700
- name: create ssh keypair
command: ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa creates=~/.ssh/id_rsa
- name: copy id_rsa to ssh directory
fetch: src=~/.ssh/id_rsa dest=./ flat=yes
- name: fetch the public key
fetch: src=~/.ssh/id_rsa.pub dest=./ flat=yes
- name: generate passwords
command: kolla-genpwd
- name: update keystone_admin_password
lineinfile: >
dest=/etc/kolla/passwords.yml
regexp='^.*keystone_admin_password:.*'
line='keystone_admin_password: {{admin_password}}'
## Enable Openstack services
- name: install openstack client on node
pip: "name=python-{{item}}client state=latest"
with_items:
- openstack
- neutron
- name: insert openstack admin.rc file
template: src=./admin-rc.j2 dest=~/admin.rc
- name: upload network create script
copy: src=./setup_net.sh dest=~/setup_net.sh
## Build the images
- name: check to see if images are already built
command: docker images
register: image_list
- name: run kolla build to build source based images
shell: 'kolla-build --type {{build_type}} --base centos --tag {{build_tag}}'
args:
executable: /bin/bash
async: 1200
poll: 0
register: kolla_build_r
ignore_errors: true
when: ansible_os_family == "RedHat" and not ('kolla/ubuntu-{{build_type}}' and "{{build_tag}}" in image_list)
- debug: var=kolla_build_r
- name: run kolla build to build source based images
shell: 'kolla-build --type {{build_type}} --base ubuntu --tag {{build_tag}}'
args:
creates: /var/log/kolla-build.log
executable: /bin/bash
async: 1200
poll: 0
register: kolla_build_u
ignore_errors: true
when: ansible_os_family == "Debian" and not ('kolla/ubuntu-{{build_type}}' and "{{build_tag}}" in image_list)
- debug: var=kolla_build_u
- name: check on kolla-build process
async_status: "jid={{ kolla_build_u.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: "{{wait_until_retries}}"
delay: 30
when: ansible_os_family == "Debian"
- name: check on kolla-build process
async_status: "jid={{ kolla_build_r.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: "{{wait_until_retries}}"
delay: 30
when: ansible_os_family == "RedHat"
- name: run kolla-ansible deploy
shell: kolla-ansible deploy |& tee /var/log/kolla-deploy.log
args:
executable: /bin/bash
creates: /var/log/kolla-deploy.log
async: 1200
poll: 0
register: ap_build
- name: check on build
async_status: jid={{ ap_build.ansible_job_id }}
register: job_result
until: job_result.finished
retries: "{{wait_until_retries}}"
delay: 30
- name: check to see if we need to force qemu emulation
command: egrep -c 'vmx|svm|0xc0f' /proc/cpuinfo
register: cpu_info
- name: update nova-compute with libvirt type to qemu if no nested virt is availble
ini_file: "dest=/etc/kolla/nova-compute/nova.conf section=libvirt option=virt_type value=qemu"
when: cpu_info.stdout == '0'
- name: update nova-compute with libvirt type to kvm for nested virt
ini_file: "dest=/etc/kolla/nova-compute/nova.conf section=libvirt option=virt_type value=kvm"
when: not cpu_info.stdout == '0'
- name: restart nova_compute container
command: docker restart nova_compute