-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate.yml
executable file
·239 lines (205 loc) · 7.09 KB
/
create.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
#!/usr/bin/env ansible-playbook
---
# This playbook demonstrates how to create a network, subnet and router on the
# Catalyst Cloud. Ansible will pick up the OpenStack environment variables from
# the operating system if an OpenStack RC file is sourced before running the
# playbook. Alternatively, you can specify the OpenStack authentication
# variables and refer to them when using the os_auth module.
- name: Deploy a cloud instance in OpenStack
hosts: localhost
vars:
os_auth_url: "{{ lookup('env','OS_AUTH_URL') }}"
os_region: "regionOne"
oc_cloud_name: "{{ lookup('env','OS_CLOUDNAME') }}"
os_project_name: "admin"
os_username: "{{ lookup('env','OS_USERNAME') }}"
os_password: "{{ lookup('env','OS_PASSWORD') }}"
# Required variables
# ssh_public_key: "/home/stack/.ssh/id_rsa.pub"
# # OpenStack authentication variables (not required if RC sourced)
#os_auth_url: https://keystone.endpoint.net:5000/v2.0
#os_region: regionOne
#os_az: some_az
#os_project_name: projectname
#os_username: username
#os_password: password
# Required variables
ssh_public_key: /home/stack/.ssh/id_rsa.pub
vars_files:
- vars/vars.yml
tasks:
# Set up an auth dir for shade
- file: path=~/.config/openstack/ state=directory mode=0755
- name: insert cerdentials into shade config
blockinfile:
create: yes
dest: ~/.config/openstack/clouds.yml
block: |
clouds:
overcloud:
auth:
auth_url: "{{ os_auth_url }}"
username: "{{ os_username }}"
password: "{{ os_password }}"
project_name: admin
- name: Generate dummyfiles for objects
blockinfile:
create: yes
dest: "{{ item.filename }}"
block: |
I am an object
My name is "{{ item.name }}"
with_items: "{{ objects }}"
# If you have sourced an OpenStack RC file, connecting to the
# Cloud is as simple as running the os_auth module with no additional
# parameters.
- name: Connect to the Cloud
os_auth:
# If you have not sourced an OpenStack RC file, you will need to pass a few
# mandatory authentication attributes, as demonstrated below.
# os_auth:
auth:
auth_url: "{{ os_auth_url }}"
username: "{{ os_username }}"
password: "{{ os_password }}"
project_name: "{{ os_project_name }}"
# ---Keystone level resources---
- name: Create tenants/projects
os_project:
name: "{{ item.name }}"
state: present
description: "{{ item.description }}"
enabled: True
with_items: "{{ projects }}"
- name: Create a user for each project
os_user:
cloud: overcloud
state: present
name: "{{ item.name }}"
password: "{{ item.password }}"
email: "{{ item.email }}"
default_project: "{{ item.default_project }}"
with_items: "{{ users }}"
# Object resources
- name: Create containers
os_object:
cloud: overcloud
state: present
container: "{{ item.name }}"
container_access: private
with_items: "{{ containers }}"
- name: Put objects
os_object:
cloud: overcloud
state: present
name: "{{ item.name }}"
filename: "{{ item.filename }}"
container: "{{ item.container }}"
with_items: "{{ objects }}"
# Images tasks
- name: Download images
get_url:
url: "{{ item.url }}"
dest: "{{ item.dest }}"
with_items: "{{ images }}"
- name: Upload images
os_image:
cloud: overcloud
name: "{{ item.name }}"
container_format: "{{ item.container_format }}"
disk_format: "{{ item.disk_format }}"
state: present
filename: "{{ item.dest }}"
kernel: "{{ item.kernel }}"
ramdisk: "{{ item.ramdisk }}"
properties:
cpu_arch: "{{ item.properties.cpu_arch }}"
distro: "{{ item.properties.distro }}"
with_items: "{{ images }}"
# Network tasks
- name: Create networks
os_network:
state: present
name: "{{ item.name }}"
external: "{{ item.external }}"
with_items: "{{ networks }}"
- name: Create subnets
os_subnet:
state: present
name: "{{ item.name }}"
network_name: "{{ item.network_name }}"
cidr: "{{ item.cidr }}"
dns_nameservers: "{{ item.dns_nameservers }}"
allocation_pool_start: "{{ item.allocation_pool_start }}"
allocation_pool_end: "{{ item.allocation_pool_end }}"
host_routes:
- destination: "{{ item.host_routes.destination }}"
nexthop: "{{ item.host_routes.nexthop }}"
with_items: "{{ subnets }}"
- name: Create routers
os_router:
state: present
name: "{{ item.name }}"
network: "{{ item.network }}"
interfaces: "{{ item.interfaces }}"
# Until the issue is resolved, need to ignore router related problems
# https://github.com/ansible/ansible-modules-core/issues/2989
ignore_errors: yes
with_items: "{{ routers }}"
- name: Create security groups
os_security_group:
state: present
name: "{{ item.name }}"
description: "{{ item.description }}"
with_items: "{{ security_groups }}"
- name: Create security group rules
os_security_group_rule:
state: present
security_group: "{{ item.security_group }}"
protocol: "{{ item.protocol }}"
port_range_min: "{{ item.port_range_min }}"
port_range_max: "{{ item.port_range_max }}"
remote_ip_prefix: "{{ item.remote_ip_prefix }}"
with_items: "{{ security_group_rules }}"
# Volumes tasks
- name: Create a volume
os_volume:
state: present
cloud: overcloud
size: "{{ item.size }}"
display_name: "{{ item.display_name }}"
with_items: "{{ volumes }}"
# Instances tasks
- name: Import SSH keypairs
os_keypair:
state: present
name: "{{ item.name }}"
public_key_file: "{{ item.public_key_file }}"
with_items: "{{ keypairs }}"
- name: Create instances
os_server:
state: present
auto_ip: no #We want to assign floating IPs ourselves
auth:
auth_url: "{{ os_auth_url }}"
username: "{{ item.user }}"
password: "{{ item.password }}"
project_name: "{{ item.project }}"
name: "{{ item.name }}"
image: "{{ item.image }}"
key_name: "{{ item.key_name }}"
flavor: "{{ item.flavor }}"
nics: "{{ item.nics }}"
security_groups: "{{ item.security_groups }}"
with_items: "{{ instances }}"
- name: Assign floating IPs
os_floating_ip:
server: "{{ item.name }}"
with_items: "{{ instances }}"
- name: Attach volumes to instances
os_server_volume:
state: present
cloud: overcloud
server: "{{ item.name }}"
volume: "{{ item.volume }}"
with_items: "{{ instances }}"