-
Notifications
You must be signed in to change notification settings - Fork 2
/
vsphere_controllers.yml
173 lines (161 loc) · 6.15 KB
/
vsphere_controllers.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
- hosts: localhost
connection: local
roles:
- { role: avinetworks.avicontroller_vmware }
gather_facts: True
tasks:
- name: "Create a VM {{ id }} folder on given datacenter"
vcenter_folder:
hostname: '{{ vcenter_host }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
validate_certs: False
datacenter_name: "{{ dc }}"
folder_name: "{{ id }}"
folder_type: vm
state: present
delegate_to: localhost
- name: "Create VM from Server Template"
vmware_guest:
hostname: '{{ vcenter_host }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
validate_certs: False
name: "{{ id }}_jumpbox"
template: "{{ server_template }}"
datacenter: "{{ dc }}"
folder: "{{ id }}"
networks:
- name: "{{ mgmt_network }}"
- name: "{{ server_network }}"
state: '{{ state | default("poweredon")}}'
wait_for_ip_address: yes
delegate_to: localhost
register: jumpbox
- name: "Create VM from Web Server Template"
vmware_guest:
hostname: '{{ vcenter_host }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
validate_certs: False
name: "{{ id }}_webserver{{ item }}"
template: "{{ server_template }}"
datacenter: "{{ dc }}"
folder: "{{ id }}"
networks:
- name: "{{ server_network }}"
state: '{{ state | default("poweredon")}}'
wait_for_ip_address: yes
with_sequence: count={{ webserver_count }}
delegate_to: localhost
register: webservers
- name: "Create VM from Avi Controller Template"
vmware_guest:
hostname: '{{ vcenter_host }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
validate_certs: False
name: "{{ id }}_controller{{ item }}"
template: "{{ avi_controller_template }}"
datacenter: "{{ dc }}"
folder: "{{ id }}"
networks:
- name: "{{ mgmt_network }}"
state: '{{ state | default("poweredon")}}'
wait_for_ip_address: yes
with_sequence: count={{ pod_count }}
delegate_to: localhost
register: controllers
- debug:
msg: "Jumphost IP: {{ jumpbox.instance.ipv4 }}"
- debug:
msg: "{{ webservers.results[item|int].instance.hw_name }} {{ webservers.results[item|int].instance.ipv4 }}"
with_sequence: start=0 end={{ webserver_count - 1 }}
- debug:
msg: "{{ controllers.results[item|int].instance.hw_name }} {{ controllers.results[item|int].instance.ipv4 }}"
with_sequence: start=0 end={{ pod_count - 1 }}
- lineinfile:
path: "{{ id }}-inventory"
line: "{{ jumpbox.instance.hw_name }} {{ jumpbox.instance.ipv4 }}"
create: yes
- lineinfile:
path: "{{ id }}-inventory"
line: "{{ webservers.results[item|int].instance.hw_name }} {{ webservers.results[item|int].instance.ipv4 }}"
with_sequence: start=0 end={{ webserver_count - 1 }}
- lineinfile:
path: "{{ id }}-inventory"
line: "{{ controllers.results[item|int].instance.hw_name }} {{ controllers.results[item|int].instance.ipv4 }}"
with_sequence: start=0 end={{ pod_count - 1 }}
- name: "Wait for the portal to become active"
uri:
url: "https://{{ controllers.results[item|int].instance.ipv4 }}/api/initial-data"
validate_certs: no
status_code: 200
register: result
until: result.status == 200
retries: 600
delay: 10
with_sequence: start=0 end={{ pod_count - 1 }}
- name: Prepare Avi credentials
set_fact:
avi_credentials: {}
- name: Prepare Avi credentials
set_fact:
avi_credentials: "{{ avi_credentials | combine({ item.key: item.value }) }}"
with_items:
- { key: 'password', value: "{{ avi_admin_password }}" }
- { key: 'api_version', value: "{{ result.results[0]['json']['version']['Version'] }}" }
- { key: 'username', value: "admin" }
- name: Update admin user account if required
avi_useraccount:
controller: "{{ controllers.results[item|int].instance.ipv4 }}"
avi_credentials: "{{ avi_credentials }}"
old_password: "{{ avi_default_password }}"
ignore_errors: yes
with_sequence: start=0 end={{ pod_count - 1 }}
- name: Basic system configuration
avi_systemconfiguration:
controller: "{{ controllers.results[item|int].instance.ipv4 }}"
avi_credentials: "{{ avi_credentials }}"
welcome_workflow_complete: true
dns_configuration:
server_list:
- addr: "{{ dns_server }}"
type: V4
ntp_configuration:
ntp_server_list:
- addr: 0.pool.ntp.org
type: DNS
- addr: 1.pool.ntp.org
type: DNS
- addr: 2.pool.ntp.org
type: DNS
- addr: 3.pool.ntp.org
type: DNS
with_sequence: start=0 end={{ pod_count - 1 }}
- name: VMware Cloud Connector Setup
avi_cloud:
controller: "{{ controllers.results[item|int].instance.ipv4 }}"
avi_credentials: "{{ avi_credentials }}"
name: Default-Cloud
vtype: CLOUD_VCENTER
dhcp_enabled: true
vcenter_configuration:
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
datacenter: "{{ dc }}"
management_network: "/api/vimgrnwruntime/?name={{ mgmt_network }}"
privilege: "WRITE_ACCESS"
vcenter_url: "{{ vcenter_host }}"
with_sequence: start=0 end={{ pod_count - 1 }}
- name: Patch VMware Cloud Connector Setup Management Network after Network Discovery
avi_cloud:
controller: "{{ controllers.results[item|int].instance.ipv4 }}"
avi_credentials: "{{ avi_credentials }}"
avi_api_update_method: patch
avi_api_patch_op: add
name: Default-Cloud
vtype: CLOUD_VCENTER
vcenter_configuration:
management_network: "/api/vimgrnwruntime/?name={{ mgmt_network }}"
with_sequence: start=0 end={{ pod_count - 1 }}