-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathvmware_guest.py
3662 lines (3314 loc) · 174 KB
/
vmware_guest.py
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This module is also sponsored by E.T.A.I. (www.etai.fr)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r'''
---
module: vmware_guest
short_description: Manages virtual machines in vCenter
description: >
This module can be used to create new virtual machines from templates or other virtual machines,
manage power state of virtual machine such as power on, power off, suspend, shutdown, reboot, restart etc.,
modify various virtual machine components like network, disk, customization etc.,
rename a virtual machine and remove a virtual machine with associated components.
author:
- Loic Blot (@nerzhul) <[email protected]>
- Philippe Dellaert (@pdellaert) <[email protected]>
- Abhijeet Kasurde (@Akasurde) <[email protected]>
notes:
- Please make sure that the user used for M(community.vmware.vmware_guest) has the correct level of privileges.
- For example, following is the list of minimum privileges required by users to create virtual machines.
- " DataStore > Allocate Space"
- " Virtual Machine > Configuration > Add New Disk"
- " Virtual Machine > Configuration > Add or Remove Device"
- " Virtual Machine > Inventory > Create New"
- " Network > Assign Network"
- " Resource > Assign Virtual Machine to Resource Pool"
- "Module may require additional privileges as well, which may be required for gathering facts - e.g. ESXi configurations."
- Use SCSI disks instead of IDE when you want to expand online disks by specifying a SCSI controller.
- Uses SysPrep for Windows VM (depends on 'guest_id' parameter match 'win') with PyVmomi.
- In order to change the VM's parameters (e.g. number of CPUs), the VM must be powered off unless the hot-add
support is enabled and the O(state=present) must be used to apply the changes.
- "For additional information please visit Ansible VMware community wiki - U(https://github.com/ansible/community/wiki/VMware)."
options:
state:
description:
- Specify the state the virtual machine should be in.
- If V(present) and virtual machine exists, ensure the virtual machine configurations conforms to task arguments.
- If V(absent) and virtual machine exists, then the specified virtual machine is removed with it's associated components.
- If set to one of V(poweredon), V(powered-on), V(poweredoff), V(powered-off),
V(present), V(restarted), V(suspended) and virtual machine does not exists, virtual machine is deployed with the given parameters.
- If set to V(poweredon) or V(powered-on) and virtual machine exists with powerstate other than powered on,
then the specified virtual machine is powered on.
- If set to V(poweredoff) or V(powered-off) and virtual machine exists with powerstate other than powered off,
then the specified virtual machine is powered off.
- If set to V(restarted) and virtual machine exists, then the virtual machine is restarted.
- If set to V(suspended) and virtual machine exists, then the virtual machine is set to suspended mode.
- If set to V(shutdownguest) or V(shutdown-guest) and virtual machine exists, then the virtual machine is shutdown.
- If set to V(rebootguest) or V(reboot-guest) and virtual machine exists, then the virtual machine is rebooted.
default: present
type: str
choices: [ absent, poweredon, powered-on, poweredoff, powered-off, present, rebootguest, reboot-guest, restarted, suspended, shutdownguest, shutdown-guest]
name:
description:
- Name of the virtual machine to work with.
- Virtual machine names in vCenter are not necessarily unique, which may be problematic, see O(name_match).
- If multiple virtual machines with same name exists, then O(folder) is required parameter to
identify uniqueness of the virtual machine.
- This parameter is required, if O(state=poweredon), O(state=powered-on), O(state=poweredoff), O(state=powered-off),
O(state=present), O(state=restarted), O(state=suspended) and virtual machine does not exists.
type: str
name_match:
description:
- If multiple virtual machines matching the name, use the first or last found.
default: 'first'
choices: [ 'first', 'last' ]
type: str
uuid:
description:
- UUID of the virtual machine to manage if known, this is VMware's unique identifier.
- This is required if O(name) is not supplied.
- If virtual machine does not exists, then this parameter is ignored.
- Please note that a supplied UUID will be ignored on virtual machine creation, as VMware creates the UUID internally.
type: str
use_instance_uuid:
description:
- Whether to use the VMware instance UUID rather than the BIOS UUID.
default: false
type: bool
template:
description:
- Template or existing virtual machine used to create new virtual machine.
- If this value is not set, virtual machine is created without using a template.
- If the virtual machine already exists, this parameter will be ignored.
- From version 2.8 onwards, absolute path to virtual machine or template can be used.
aliases: [ 'template_src' ]
type: str
is_template:
description:
- Flag the instance as a template.
- This will mark the given virtual machine as template.
- Note, this may need to be done in a dedicated task invocation that is not making
any other changes. For example, user cannot change the state from powered-on to
powered-off AND save as template in the same task.
- See M(community.vmware.vmware_guest) source for more details.
default: false
type: bool
folder:
description:
- Destination folder, absolute path to find an existing guest or create the new guest.
- "The folder should include the datacenter. ESXi's datacenter is ha-datacenter."
- 'If multiple machines are found with same name, this parameter is used to identify'
- 'uniqueness of the virtual machine.'
- 'Examples:'
- ' folder: /ha-datacenter/vm'
- ' folder: ha-datacenter/vm'
- ' folder: /datacenter1/vm'
- ' folder: datacenter1/vm'
- ' folder: /datacenter1/vm/folder1'
- ' folder: datacenter1/vm/folder1'
- ' folder: /folder1/datacenter1/vm'
- ' folder: folder1/datacenter1/vm'
- ' folder: /folder1/datacenter1/vm/folder2'
type: str
hardware:
type: dict
default: {}
description:
- "Manage virtual machine's hardware attributes."
suboptions:
hotadd_cpu:
type: bool
description: Allow virtual CPUs to be added while the virtual machine is running.
hotremove_cpu:
type: bool
description: Allow virtual CPUs to be removed while the virtual machine is running.
hotadd_memory:
type: bool
description: Allow memory to be added while the virtual machine is running.
memory_mb:
type: int
description: Amount of memory in MB.
num_cpus:
type: int
description:
- Number of CPUs.
- Must be a multiple of O(hardware.num_cpu_cores_per_socket).
- For example, to create a VM with 2 sockets of 4 cores, specify O(hardware.num_cpus) as 8 and O(hardware.num_cpu_cores_per_socket) as 4.
num_cpu_cores_per_socket:
type: int
description: Number of Cores Per Socket.
cpu_shares_level:
type: str
choices: [ 'low', 'normal', 'high', 'custom' ]
description:
- The allocation level of CPU resources for the virtual machine.
version_added: '3.2.0'
cpu_shares:
type: int
description:
- The number of shares of CPU allocated to this virtual machine
- cpu_shares_level will automatically be set to 'custom'
version_added: '3.2.0'
vpmc_enabled:
version_added: '3.2.0'
type: bool
description: Enable virtual CPU Performance Counters.
scsi:
type: str
description:
- Valid values are V(buslogic), V(lsilogic), V(lsilogicsas) and V(paravirtual).
- V(paravirtual) is default.
choices: [ 'buslogic', 'lsilogic', 'lsilogicsas', 'paravirtual' ]
secure_boot:
type: bool
description: Whether to enable or disable (U)EFI secure boot.
memory_reservation_lock:
type: bool
description:
- If set V(true), memory resource reservation for the virtual machine.
max_connections:
type: int
description:
- Maximum number of active remote display connections for the virtual machines.
mem_limit:
type: int
description:
- The memory utilization of a virtual machine will not exceed this limit.
- Unit is MB.
mem_reservation:
type: int
description: The amount of memory resource that is guaranteed available to the virtual machine.
aliases: [ 'memory_reservation' ]
mem_shares_level:
type: str
description:
- The allocation level of memory resources for the virtual machine.
choices: [ 'low', 'normal', 'high', 'custom' ]
version_added: '3.2.0'
mem_shares:
type: int
description:
- The number of shares of memory allocated to this virtual machine
- mem_shares_level will automatically be set to 'custom'
version_added: '3.2.0'
cpu_limit:
type: int
description:
- The CPU utilization of a virtual machine will not exceed this limit.
- Unit is MHz.
cpu_reservation:
type: int
description: The amount of CPU resource that is guaranteed available to the virtual machine.
version:
type: str
description:
- The Virtual machine hardware versions.
- Default is 10 (ESXi 5.5 and onwards).
- If set to V(latest), the specified virtual machine will be upgraded to the most current hardware version supported on the host.
- Please check VMware documentation for correct virtual machine hardware version.
- Incorrect hardware version may lead to failure in deployment. If hardware version is already equal to the given.
boot_firmware:
type: str
description: Choose which firmware should be used to boot the virtual machine.
choices: [ 'bios', 'efi' ]
nested_virt:
type: bool
description:
- Enable nested virtualization.
virt_based_security:
type: bool
description:
- Enable Virtualization Based Security feature for Windows on ESXi 6.7 and later, from hardware version 14.
- Supported Guest OS are Windows 10 64 bit, Windows Server 2016, Windows Server 2019 and later.
- The firmware of virtual machine must be EFI and secure boot must be enabled.
- Virtualization Based Security depends on nested virtualization and Intel Virtualization Technology for Directed I/O.
- Deploy on unsupported ESXi, hardware version or firmware may lead to failure or deployed VM with unexpected configurations.
iommu:
type: bool
description: Flag to specify if I/O MMU is enabled for this virtual machine.
encryption:
type: dict
default: {}
description:
- Manage virtual machine encryption settings
version_added: '3.9.0'
suboptions:
encrypted_vmotion:
type: str
description: Controls encryption for live migrations with vmotion
choices: ['disabled', 'opportunistic', 'required']
encrypted_ft:
type: str
description: Controls encryption for fault tolerance replication
choices: ['disabled', 'opportunistic', 'required']
guest_id:
type: str
description:
- Set the guest ID.
- This field is required when creating a virtual machine, not required when creating from the template.
- >
Valid values are referenced here:
U(https://code.vmware.com/apis/358/doc/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html)
disk:
description:
- A list of disks to add.
- Shrinking disks is not supported.
- Removing existing disks of the virtual machine is not supported.
- 'Attributes O(disk[].controller_type), O(disk[].controller_number), O(disk[].unit_number) are used to configure multiple types of disk
controllers and disks for creating or reconfiguring virtual machine.'
type: list
default: []
elements: dict
suboptions:
size:
description:
- Disk storage size.
- Please specify storage unit like [kb, mb, gb, tb].
type: str
size_kb:
description: Disk storage size in kb.
type: int
size_mb:
description: Disk storage size in mb.
type: int
size_gb:
description: Disk storage size in gb.
type: int
size_tb:
description: Disk storage size in tb.
type: int
type:
description:
- Type of disk.
- If not specified, disk type is inherited from the source VM or template when cloned and thick disk, no eagerzero otherwise.
type: str
choices: [ 'thin', 'thick', 'eagerzeroedthick' ]
datastore:
type: str
description:
- The name of datastore which will be used for the disk.
- If O(disk[].autoselect_datastore) is set to True, will select the less used datastore whose name contains this "disk.datastore" string.
filename:
type: str
description:
- Existing disk image to be used.
- Filename must already exist on the datastore.
- Specify filename string in C([datastore_name] path/to/file.vmdk) format.
autoselect_datastore:
type: bool
description:
- Select the less used datastore.
- O(disk[].datastore) and O(disk[].autoselect_datastore) will not be used if O(datastore) is specified outside this O(disk[]) configuration.
disk_mode:
type: str
choices: ['persistent', 'independent_persistent', 'independent_nonpersistent']
description:
- Type of disk mode.
- If V(persistent) specified, changes are immediately and permanently written to the virtual disk. This is default.
- If V(independent_persistent) specified, same as persistent, but not affected by snapshots.
- If V(independent_nonpersistent) specified, changes to virtual disk are made to a redo log and discarded at power off,
but not affected by snapshots.
controller_type:
type: str
choices: ['buslogic', 'lsilogic', 'lsilogicsas', 'paravirtual', 'sata', 'nvme']
description:
- Type of disk controller.
Set this type on not supported ESXi or VM hardware version will lead to failure in deployment.
- When set to V(sata), please make sure O(disk[].unit_number) is correct and not used by SATA CDROMs.
- If set to V(sata) type, please make sure O(disk[].controller_number) and O(disk[].unit_number) are set correctly when O(cdrom=sata).
controller_number:
type: int
choices: [0, 1, 2, 3]
description:
- Disk controller bus number.
- The maximum number of same type controller is 4 per VM.
unit_number:
type: int
description:
- Disk Unit Number.
- Valid value range from 0 to 15 for SCSI controller, except 7.
- Valid value range from 0 to 14 for NVME controller.
- Valid value range from 0 to 29 for SATA controller.
- O(disk[].controller_type), O(disk[].controller_number) and O(disk[].unit_number) are required when creating or reconfiguring VMs
with multiple types of disk controllers and disks.
- When creating new VM, the first configured disk in the O(disk[]) list will be "Hard Disk 1".
nvdimm:
description:
- Add or remove a virtual NVDIMM device to the virtual machine.
- VM virtual hardware version must be 14 or higher on vSphere 6.7 or later.
- Verify that guest OS of the virtual machine supports PMem before adding virtual NVDIMM device.
- Verify that you have the I(Datastore.Allocate) space privilege on the virtual machine.
- Make sure that the host or the cluster on which the virtual machine resides has available PMem resources.
- To add or remove virtual NVDIMM device to the existing virtual machine, it must be in power off state.
type: dict
default: {}
suboptions:
state:
type: str
description:
- If set to V(absent), then the NVDIMM device with specified O(nvdimm.label) will be removed.
choices: ['present', 'absent']
size_mb:
type: int
description: Virtual NVDIMM device size in MB.
default: 1024
label:
type: str
description:
- The label of the virtual NVDIMM device to be removed or configured, e.g., "NVDIMM 1".
- 'This parameter is required when O(nvdimm.state=absent), or O(nvdimm.state=present) to reconfigure NVDIMM device
size. When add a new device, please do not set.'
cdrom:
description:
- A list of CD-ROM configurations for the virtual machine.
- For V(ide) controller, hot-add or hot-remove CD-ROM is not supported.
type: list
default: []
elements: dict
suboptions:
type:
type: str
description:
- The type of CD-ROM.
- With V(none) the CD-ROM will be disconnected but present.
choices: [ 'none', 'client', 'iso' ]
default: client
iso_path:
type: str
description:
- The datastore path to the ISO file to use, in the form of C([datastore1] path/to/file.iso).
- Required if type is set V(iso).
controller_type:
type: str
description:
- When set to V(sata), please make sure O(cdrom[].unit_number) is correct and not used by SATA disks.
choices: [ 'ide', 'sata' ]
default: ide
controller_number:
type: int
description:
- For O(cdrom[].controller_type=ide), valid value is 0 or 1.
- For O(cdrom[].controller_type=sata), valid value is 0 to 3.
unit_number:
type: int
description:
- For O(cdrom[].controller_type=ide), valid value is 0 or 1.
- For O(cdrom[].controller_type=sata), valid value is 0 to 29.
- O(cdrom[].controller_number) and O(cdrom[].unit_number) are mandatory attributes.
state:
type: str
description:
- If set to V(absent), then the specified CD-ROM will be removed.
choices: [ 'present', 'absent' ]
default: present
resource_pool:
description:
- Use the given resource pool for virtual machine operation.
- Resource pool should be child of the selected host parent.
- When not specified I(Resources) is taken as default value.
type: str
wait_for_ip_address:
description:
- Wait until vCenter detects an IP address for the virtual machine.
- This requires vmware-tools (vmtoolsd) to properly work after creation.
- "vmware-tools needs to be installed on the given virtual machine in order to work with this parameter."
default: false
type: bool
wait_for_ip_address_timeout:
description:
- Define a timeout (in seconds) for the wait_for_ip_address parameter.
default: '300'
type: int
wait_for_customization_timeout:
description:
- Define a timeout (in seconds) for the wait_for_customization parameter.
- Be careful when setting this value since the time guest customization took may differ among guest OSes.
default: '3600'
type: int
wait_for_customization:
description:
- Wait until vCenter detects all guest customizations as successfully completed.
- When enabled, the VM will automatically be powered on.
- "If vCenter does not detect guest customization start or succeed, failed events after time
O(wait_for_customization_timeout) parameter specified, warning message will be printed and task result is fail."
default: false
type: bool
state_change_timeout:
description:
- If the O(state=shutdownguest), by default the module will return immediately after sending the shutdown signal.
- If this argument is set to a positive integer, the module will instead wait for the virtual machine to reach the poweredoff state.
- The value sets a timeout in seconds for the module to wait for the state change.
default: 0
type: int
snapshot_src:
description:
- Name of the existing snapshot to use to create a clone of a virtual machine.
- While creating linked clone using O(linked_clone) parameter, this parameter is required.
type: str
linked_clone:
description:
- Whether to create a linked clone from the snapshot specified.
- If specified, then O(snapshot_src) is required parameter.
default: false
type: bool
force:
description:
- Ignore warnings and complete the actions.
- This parameter is useful while removing virtual machine which is powered on state.
- 'This module reflects the VMware vCenter API and UI workflow, as such, in some cases the `force` flag will
be mandatory to perform the action to ensure you are certain the action has to be taken, no matter what the consequence.
This is specifically the case for removing a powered on the virtual machine when O(state=absent).'
default: false
type: bool
delete_from_inventory:
description:
- Whether to delete Virtual machine from inventory or delete from disk.
default: false
type: bool
datacenter:
description:
- Destination datacenter for the deploy operation.
default: ha-datacenter
type: str
cluster:
description:
- The cluster name where the virtual machine will run.
- This is a required parameter, if O(esxi_hostname) is not set.
- O(esxi_hostname) and O(cluster) are mutually exclusive parameters.
type: str
esxi_hostname:
description:
- The ESXi hostname where the virtual machine will run.
- This is a required parameter, if O(cluster) is not set.
- O(esxi_hostname) and O(cluster) are mutually exclusive parameters.
type: str
advanced_settings:
description:
- Define a list of advanced settings to be added to the VMX config.
- An advanced settings object takes the two fields C(key) and C(value).
- Incorrect key and values will be ignored.
elements: dict
type: list
default: []
annotation:
description:
- A note or annotation to include in the virtual machine.
type: str
aliases: [ 'notes' ]
customvalues:
description:
- Define a list of custom values to set on virtual machine.
- A custom value object takes the two fields C(key) and C(value).
- Incorrect key and values will be ignored.
elements: dict
type: list
default: []
networks:
description:
- A list of networks (in the order of the NICs).
- Removing NICs is not allowed, while reconfiguring the virtual machine.
- The I(type), I(ip), I(netmask), I(gateway), I(domain), I(dns_servers) options don't set to a guest when creating a blank new virtual machine.
They are set by the customization via vmware-tools.
If you want to set the value of the options to a guest, you need to clone from a template with installed OS and vmware-tools (also Perl when Linux).
type: list
default: []
elements: dict
suboptions:
name:
type: str
description:
- Name of the portgroup or distributed virtual portgroup for this interface.
- Required per entry.
- When specifying distributed virtual portgroup make sure given O(esxi_hostname) or O(cluster) is associated with it.
vlan:
type: int
description:
- VLAN number for this interface.
- Required per entry.
device_type:
type: str
description:
- Virtual network device.
- Valid value can be one of C(e1000), C(e1000e), C(pcnet32), C(vmxnet2), C(vmxnet3), C(sriov).
- C(vmxnet3) is default.
- Optional per entry.
- Used for virtual hardware.
mac:
type: str
description:
- Customize MAC address.
- Optional per entry.
- Used for virtual hardware.
dvswitch_name:
type: str
description:
- Name of the distributed vSwitch.
- Optional per entry.
- Used for virtual hardware.
type:
type: str
description:
- Type of IP assignment.
- Valid values are one of C(dhcp), C(static).
- C(dhcp) is default.
- Optional per entry.
- Used for OS customization.
ip:
type: str
description:
- Static IP address. Implies C(type=static).
- Optional per entry.
- Used for OS customization.
netmask:
type: str
description:
- Static netmask required for C(ip).
- Optional per entry.
- Used for OS customization.
gateway:
type: str
description:
- Static gateway.
- Optional per entry.
- Used for OS customization.
typev6:
version_added: '4.1.0'
type: str
description:
- Type of IP assignment.
- Valid values are one of C(dhcp), C(static).
- C(dhcp) is default.
- Optional per entry.
- Used for OS customization.
ipv6:
version_added: '4.1.0'
type: str
description:
- Static IP address. Implies C(type=static).
- Optional per entry.
- Used for OS customization.
netmaskv6:
version_added: '4.1.0'
type: str
description:
- Static netmask required for C(ip).
- Optional per entry.
- Used for OS customization.
gatewayv6:
version_added: '4.1.0'
type: str
description:
- Static gateway.
- Optional per entry.
- Used for OS customization.
dns_servers:
type: str
description:
- DNS servers for this network interface (Windows).
- Optional per entry.
- Used for OS customization.
domain:
type: str
description:
- Domain name for this network interface (Windows).
- Optional per entry.
- Used for OS customization.
connected:
type: bool
description:
- Indicates whether the NIC is currently connected.
start_connected:
type: bool
description:
- Specifies whether or not to connect the device when the virtual machine starts.
customization:
description:
- Parameters for OS customization when cloning from the template or the virtual machine, or apply to the existing virtual machine directly.
- Not all operating systems are supported for customization with respective vCenter version,
please check VMware documentation for respective OS customization.
- For supported customization operating system matrix, (see U(http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf))
- Linux based OSes requires Perl package to be installed for OS customizations.
suboptions:
existing_vm:
type: bool
description:
- If set to V(true), do OS customization on the specified virtual machine directly.
- Common for Linux and Windows customization.
dns_servers:
type: list
elements: str
description:
- List of DNS servers to configure.
- Common for Linux and Windows customization.
dns_suffix:
type: list
elements: str
description:
- List of domain suffixes, also known as DNS search path.
- Default C(domain) parameter.
- Common for Linux and Windows customization.
domain:
type: str
description:
- DNS domain name to use.
- Common for Linux and Windows customization.
hostname:
type: str
description:
- Computer hostname.
- Default is shortened O(name) parameter.
- Allowed characters are alphanumeric (uppercase and lowercase) and minus, rest of the characters are dropped as per RFC 952.
- Common for Linux and Windows customization.
timezone:
type: str
description:
- Timezone.
- See List of supported time zones for different vSphere versions in Linux/Unix.
- Common for Linux and Windows customization.
- L(Windows, https://msdn.microsoft.com/en-us/library/ms912391.aspx).
hwclockUTC:
type: bool
description:
- Specifies whether the hardware clock is in UTC or local time.
- Specific to Linux customization.
script_text:
type: str
description:
- Script to run with shebang.
- Needs to be enabled in vmware tools with vmware-toolbox-cmd config set deployPkg enable-custom-scripts true
- https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-9A5093A5-C54F-4502-941B-3F9C0F573A39.html
- Specific to Linux customization.
version_added: '3.1.0'
autologon:
type: bool
description:
- Auto logon after virtual machine customization.
- Specific to Windows customization.
autologoncount:
type: int
description:
- Number of autologon after reboot.
- Specific to Windows customization.
- Ignored if O(customization.autologon) is unset or set to O(customization.autologon=false).
- If unset, 1 will be used.
domainadmin:
type: str
description:
- User used to join in AD domain.
- Required if O(customization.joindomain) specified.
- Specific to Windows customization.
domainadminpassword:
type: str
description:
- Password used to join in AD domain.
- Required if O(customization.joindomain) specified.
- Specific to Windows customization.
fullname:
type: str
description:
- Server owner name.
- Specific to Windows customization.
- If unset, "Administrator" will be used as a fall-back.
joindomain:
type: str
description:
- AD domain to join.
- Not compatible with O(customization.joinworkgroup).
- Specific to Windows customization.
joinworkgroup:
type: str
description:
- Workgroup to join.
- Not compatible with O(customization.joindomain).
- Specific to Windows customization.
- If unset, "WORKGROUP" will be used as a fall-back.
orgname:
type: str
description:
- Organization name.
- Specific to Windows customization.
- If unset, "ACME" will be used as a fall-back.
password:
type: str
description:
- Local administrator password.
- If not defined, the password will be set to blank (that is, no password).
- Specific to Windows customization.
productid:
type: str
description:
- Product ID.
- Specific to Windows customization.
runonce:
type: list
elements: str
description:
- List of commands to run at first user logon.
- Specific to Windows customization.
domain_ou:
type: str
description:
- The full LDAP path name of the OU to which the computer belongs.
- Specific to Windows customization.
- Work for vSphere 8.0U2 and above
type: dict
default: {}
vapp_properties:
description:
- A list of vApp properties.
- 'For full list of attributes and types refer to: U(https://code.vmware.com/apis/704/vsphere/vim.vApp.PropertyInfo.html)'
type: list
default: []
elements: dict
suboptions:
id:
type: str
description:
- Property ID.
- Required per entry.
value:
type: str
description:
- Property value.
type:
type: str
description:
- Value type, string type by default.
operation:
type: str
description:
- The C(remove) attribute is required only when removing properties.
customization_spec:
description:
- Unique name identifying the requested customization specification.
- If set, then overrides O(customization) parameter values.
type: str
datastore:
description:
- Specify datastore or datastore cluster to provision virtual machine.
- This parameter takes precedence over O(disk[].datastore) parameter.
- This parameter can be used to override datastore or datastore cluster setting
of the virtual machine when deployed from the template.
- Please see example for more usage.
type: str
convert:
description:
- Specify convert disk type while cloning template or virtual machine.
choices: [ 'thin', 'thick', 'eagerzeroedthick' ]
type: str
extends_documentation_fragment:
- community.vmware.vmware.documentation
'''
EXAMPLES = r'''
- name: Create a virtual machine on given ESXi hostname
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: /DC1/vm/
name: test_vm_0001
state: poweredon
guest_id: centos64Guest
# This is hostname of particular ESXi server on which user wants VM to be deployed
esxi_hostname: "{{ esxi_hostname }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 512
num_cpus: 4
scsi: paravirtual
networks:
- name: VM Network
mac: aa:bb:dd:aa:00:14
ip: 10.10.10.100
netmask: 255.255.255.0
device_type: vmxnet3
wait_for_ip_address: true
wait_for_ip_address_timeout: 600
delegate_to: localhost
register: deploy_vm
- name: Create a virtual machine from a template
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: /testvms
name: testvm_2
state: poweredon
template: template_el7
disk:
- size_gb: 10
type: thin
datastore: g73_datastore
# Add another disk from an existing VMDK
- filename: "[datastore1] testvms/testvm_2_1/testvm_2_1.vmdk"
hardware:
memory_mb: 512
num_cpus: 6
num_cpu_cores_per_socket: 3
scsi: paravirtual
memory_reservation_lock: true
mem_limit: 8096
mem_reservation: 4096
cpu_shares_level: "high"
mem_shares_level: "high"
cpu_limit: 8096
cpu_reservation: 4096
max_connections: 5
hotadd_cpu: true
hotremove_cpu: true
hotadd_memory: false
version: 12 # Hardware version of virtual machine
boot_firmware: "efi"
cdrom:
- controller_number: 0
unit_number: 0
state: present
type: iso
iso_path: "[datastore1] livecd.iso"
networks:
- name: VM Network
mac: aa:bb:dd:aa:00:14
wait_for_ip_address: true
delegate_to: localhost
register: deploy
- name: Clone a virtual machine from Windows template and customize
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: datacenter1
cluster: cluster
name: testvm-2
template: template_windows
networks:
- name: VM Network
ip: 192.168.1.100
netmask: 255.255.255.0
gateway: 192.168.1.1
mac: aa:bb:dd:aa:00:14
domain: my_domain
dns_servers:
- 192.168.1.1
- 192.168.1.2
- vlan: 1234
type: dhcp
customization:
autologon: true
dns_servers:
- 192.168.1.1
- 192.168.1.2
domain: my_domain
password: new_vm_password
runonce:
- powershell.exe -ExecutionPolicy Unrestricted -File C:\Windows\Temp\ConfigureRemotingForAnsible.ps1 -ForceNewSSLCert -EnableCredSSP
delegate_to: localhost
- name: Clone a virtual machine from Linux template and customize
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter }}"
state: present
folder: /DC1/vm
template: "{{ template }}"
name: "{{ vm_name }}"
cluster: DC1_C1
networks:
- name: VM Network
ip: 192.168.10.11
netmask: 255.255.255.0
wait_for_ip_address: true
customization:
domain: "{{ guest_domain }}"
dns_servers:
- 8.9.9.9
- 7.8.8.9
dns_suffix:
- example.com
- example2.com
script_text: |
#!/bin/bash
touch /tmp/touch-from-playbook
delegate_to: localhost
- name: Rename a virtual machine (requires the virtual machine's uuid)
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
uuid: "{{ vm_uuid }}"
name: new_name
state: present
delegate_to: localhost
- name: Remove a virtual machine by uuid
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
uuid: "{{ vm_uuid }}"
state: absent
delegate_to: localhost
- name: Remove a virtual machine from inventory
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: vm_name
delete_from_inventory: true
state: absent
delegate_to: localhost
- name: Manipulate vApp properties
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: vm_name
state: present
vapp_properties:
- id: remoteIP
category: Backup
label: Backup server IP
type: string
value: 10.10.10.1
- id: old_property
operation: remove
delegate_to: localhost
- name: Set powerstate of a virtual machine to poweroff by using UUID
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"