-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_one_se.yml
131 lines (122 loc) · 5.83 KB
/
deploy_one_se.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
# code: language=ansible
---
- name: '{{ "Generate token for SE: " + se_item.name }}'
vmware.alb.avi_api_session:
avi_credentials: "{{ avi_credentials }}"
api_context: "{{ avi_api_context | default(omit) }}"
http_method: "get"
path: "securetoken-generate"
params:
cloud_uuid: "{{ cloud_uuid }}"
register: secure_token
delegate_to: "localhost"
- name: '{{ "Deploy SE VM: " + se_item.name }}'
community.vmware.vmware_deploy_ovf:
hostname: "{{ cloud_parameters.vcenter }}"
username: "{{ cloud_parameters.username }}"
password: "{{ cloud_parameters.password }}"
datacenter: "{{ cloud_parameters.datacenter }}"
cluster: "{{ cloud_parameters.cluster }}"
datastore: "{{ cloud_parameters.datastore }}"
name: "{{ se_item.name }}"
networks: '{u"Management":u"{{ se_mgmt_pg }}",
u"Data Network 1":u"{{ se_item.data_nics1.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 2":u"{{ se_item.data_nics2.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 3":u"{{ se_item.data_nics3.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 4":u"{{ se_item.data_nics4.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 5":u"{{ se_item.data_nics5.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 6":u"{{ se_item.data_nics6.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 7":u"{{ se_item.data_nics7.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 8":u"{{ se_item.data_nics8.pg_name | default(avi_internal_pg, true) }}",
u"Data Network 9":u"{{ se_item.data_nics9.pg_name | default(avi_internal_pg, true) }}"}'
ovf: "./se.ova"
validate_certs: "no"
folder: '{{ cloud_parameters.datacenter + "/vm/" + cloud_parameters.no_access_folder }}'
properties: '{u"AVICNTRL_CLUSTERUUID":u"{{ cluster_uuid }}",
u"AVICNTRL_AUTHTOKEN":u"{{ secure_token.obj.auth_token }}",
u"avi.default-gw.SE":u"{{ se_gw }}",
u"avi.DNS.SE":u"{{ se_dns }}",
u"AVISETYPE":u"{{ avi_se_type }}",
u"avi.mgmt-ip.SE":u"{{ se_item.ip }}",
u"avi.mgmt-mask.SE":u"{{ se_mask }}",
u"AVICNTRL": u"{{ secure_token.obj.leader_ip }}"}'
power_on: "yes"
allow_duplicates: "no"
register: se_vm
- name: '{{ "Wait for SE to connect to Controller: " + se_item.name }}'
vmware.alb.avi_api_session:
avi_credentials: "{{ avi_credentials }}"
api_context: "{{ avi_api_context | default(omit) }}"
http_method: "get"
path: "serviceengine"
params:
name: "{{ se_item.ip }}"
cloud_uuid: "{{ cloud_uuid }}"
register: api_results
until: api_results.obj.count == 1 and api_results.obj.results[0].se_connected == true
retries: 50
delay: 8
delegate_to: "localhost"
- name: "Set some facts"
ansible.builtin.set_fact:
se_vnics: "{{ api_results.obj.results[0].data_vnics }}"
vm_mac_addresses: {}
se_mac_addresses: {}
mac_mapping: {}
vnic_list: []
- name: "Enumerate SE vNICs"
ansible.builtin.set_fact:
se_mac_addresses: "{{ se_mac_addresses | combine( { item.mac_address: item.linux_name } ) }}"
loop: "{{ se_vnics | flatten(levels=1) }}"
- name: "Enumerate VM vNICs"
ansible.builtin.set_fact:
vm_mac_addresses: "{{ vm_mac_addresses | combine( { item.value.macaddress: item.key.replace('hw_eth','data_nics')} ) }}"
when: "'hw_eth' in item.key and item.key != 'hw_eth0'"
loop: "{{ se_vm.instance | dict2items }}"
- name: '{{ "Mapping out SE interfaces:" + se_item.name }}'
ansible.builtin.set_fact:
mac_mapping: "{{ mac_mapping | combine( { se_mac_addresses[item.key]: item.value } ) }}"
loop: "{{ vm_mac_addresses | dict2items }}"
- name: '{{ "Preparing SE interfaces with static IPs: " + se_item.name }}'
ansible.builtin.set_fact:
vnic_list: "{{ vnic_list + [ item|combine({'vnic_networks':[{'ip':{'mask': se_item[mac_mapping[item.linux_name]]['mask'],'ip_addr': {'type': 'V4', 'addr': se_item[mac_mapping[item.linux_name]]['ip']}},'ctlr_alloc': False,'mode': 'STATIC'}]})] }}"
loop: "{{ se_vnics | flatten(levels=1) }}"
when: "item.linux_name in mac_mapping
and
se_item[mac_mapping[item.linux_name]]['pg_name'] is defined
and
se_item[mac_mapping[item.linux_name]]['pg_name'] != None
and
se_item[mac_mapping[item.linux_name]]['ip'] is defined
and
se_item[mac_mapping[item.linux_name]]['ip'] != None
and
se_item[mac_mapping[item.linux_name]]['mask'] is defined
and
se_item[mac_mapping[item.linux_name]]['mask'] != None"
- name: '{{ "Preparing SE interfaces with dynamic IPs: " + se_item.name }}'
ansible.builtin.set_fact:
vnic_list: "{{ vnic_list + [ item | combine({'dhcp_enabled': True}) ] }}"
vars:
new_item: "{ 'dhcp_enabled': 'true' }"
loop: "{{ se_vnics | flatten(levels=1) }}"
when: "item.linux_name in mac_mapping
and
se_item[mac_mapping[item.linux_name]]['pg_name'] is defined
and
se_item[mac_mapping[item.linux_name]]['pg_name'] != None
and
(se_item[mac_mapping[item.linux_name]]['ip'] is undefined
or
se_item[mac_mapping[item.linux_name]]['ip'] == None)"
- name: '{{ "Configure data NIC IP addresses: " + se_item.name }}'
vmware.alb.avi_serviceengine:
avi_credentials: "{{ avi_credentials }}"
api_context: "{{ avi_api_context | default(omit) }}"
avi_api_update_method: patch
avi_api_patch_op: replace
name: "{{ se_item.ip }}"
cloud_ref: '{{ "/api/cloud/?name=" + cloud_name }}'
data_vnics: "{{ vnic_list }}"
se_group_ref: "{{ segroup_url }}"
delegate_to: "localhost"