Repository navigation
Expand file tree
/
Copy pathprep.yml
More file actions
105 lines (93 loc) · 3.64 KB
/
Copy pathprep.yml
File metadata and controls
105 lines (93 loc) · 3.64 KB
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
---
- name: "Prepare new lab pod"
hosts: localhost
gather_facts: false
vars_files:
- defaults/main.yml
- "{{ mainvars }}"
tasks:
#- include_vars: "{{ mainvars }}"
- debug:
msg:
- "vcenter_address: {{ vcenter_address|default(esxi_address) }}"
- "lab name: {{ lab_name|default('') }}"
- "lab_vm_datastore: {{ lab_vm_datastore|default('') }}"
- "lab_lan1_portgroup: {{ lab_lan1_portgroup|default('') }}"
- "lab_lan2_portgroup: {{ lab_lan2_portgroup|default('') }}"
- name: Get Portgroup info
community.vmware.vmware_portgroup_info:
hostname: "{{ vcenter_address|default(esxi_address) }}"
username: "{{ vcenter_username|default(esxi_username) }}"
password: "{{ vcenter_password|default(esxi_password) }}"
validate_certs: no
cluster_name: "{{ vcenter_cluster|default('') }}"
delegate_to: localhost
register: portgroupinfo
- name: get used vlans
set_fact:
all_vlans: "{{ lookup('sequence', 'start='+ vlan_start|string +' count='+ vlan_count|string, wantlist=true)|map('int') }}"
used_vlans: "{{ portgroupinfo.hosts_portgroup_info[portgroupinfo.hosts_portgroup_info|first] |
selectattr('vswitch', 'eq', esxi_vswitch) |
map(attribute='vlan_id') }}"
- name: get unused vlans
set_fact:
unused_vlans: "{{ all_vlans | difference(used_vlans) | sort }}"
- name: VM Portgroup to all hosts in a cluster
community.vmware.vmware_portgroup:
hostname: "{{ vcenter_address|default(esxi_address) }}"
username: "{{ vcenter_username|default(esxi_username) }}"
password: "{{ vcenter_password|default(esxi_password) }}"
validate_certs: no
cluster_name: "{{ vcenter_cluster|default('') }}"
switch: "{{ esxi_vswitch }}"
portgroup: "{{ lab_lan1_portgroup }}"
vlan_id: "{{ unused_vlans[0] }}"
delegate_to: localhost
when: lab_lan1_portgroup|default('') != ""
- name: VM Portgroup to all hosts in a cluster
community.vmware.vmware_portgroup:
hostname: "{{ vcenter_address|default(esxi_address) }}"
username: "{{ vcenter_username|default(esxi_username) }}"
password: "{{ vcenter_password|default(esxi_password) }}"
validate_certs: no
cluster_name: "{{ vcenter_cluster|default('') }}"
switch: "{{ esxi_vswitch }}"
portgroup: "{{ lab_lan2_portgroup }}"
vlan_id: "{{ unused_vlans[1] }}"
delegate_to: localhost
when: lab_lan2_portgroup|default('') != ""
- name: Create Lab Volume
na_ontap_volume:
state: present
name: "{{ lab_vm_datastore }}"
aggregate_name: "{{ ontap_aggregate }}"
size: "{{ ontap_vol_size_gb }}"
size_unit: gb
space_guarantee: none
volume_security_style: unix
junction_path: "/{{ ontap_vol_labs }}/{{ lab_vm_datastore }}"
vserver: "{{ ontap_svm_name }}"
hostname: "{{ ontap_address }}"
username: admin
password: "{{ ontap_password }}"
https: true
validate_certs: false
when:
- ontap_address|default('') != ""
- name: Mount NFS labs datastore to ESXi
vmware_host_datastore:
hostname: '{{ item }}'
username: "{{ esxi_username|default('root') }}"
password: '{{ esxi_password|default(vcenter_password) }}'
esxi_hostname: '{{ esxi_hostname }}'
validate_certs: no
datastore_name: "{{ lab_vm_datastore }}"
datastore_type: 'nfs'
nfs_server: '{{ ontap_svm_address }}'
nfs_path: "/{{ ontap_vol_labs }}/{{ lab_vm_datastore }}"
nfs_ro: no
state: present
delegate_to: localhost
with_items: "{{cluster_hosts}}"
when:
- ontap_address|default('') != ""