VMware Guest
Resumo
Este módulo pode ser usado para criar novas máquinas virtuais a partir de modelos ou outras máquinas virtuais, gerenciar o estado de energia da máquina virtual, como ligar, desligar, suspender, desligar, reiniciar, reiniciar etc., modificar vários componentes da máquina virtual, como rede, disco, personalização, etc., renomeie uma máquina virtual e remova uma máquina virtual com componentes associados.
Requisitos
Os requisitos abaixo são necessários no host que executa este módulo.
- PyVmomi
Parâmetros
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
state | string |
|
|
name | string | | Nome da máquina virtual. Este é um parâmetro obrigatório, se o parâmetro uuid ou moid não for fornecido. |
name_match | string |
| Se várias máquinas virtuais corresponderem ao nome, use a primeira ou a última encontrada |
uuid | string | | UUID da instância para reunir fatos, se conhecido, este é o identificador exclusivo da VMware. Este é um parâmetro obrigatório, se o parâmetro name ou moid não for fornecido. |
use_instance_uuid | bool |
| Se deve usar o UUID da instância VMware em vez do UUID do BIOS |
template | string | |
|
is_template | bool |
|
|
folder | string | | Pasta de destino, caminho absoluto ou relativo para encontrar um convidado existente. Este é um parâmetro obrigatório, apenas se várias VMs forem encontradas com o mesmo nome. A pasta deve incluir o datacenter. O datacenter da ESX é ha-datacenter Exemplos: 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 |
hardware | dict | |
|
guest-id | string | |
|
use_instance_uuid | boolean |
| Se deve usar o UUID da instância do VMware em vez do UUID do BIOS. |
disk | list / elements=dictionary | |
|
nvdimm | dict | |
|
cdrom | raw | |
|
resource_pool | string | |
|
wait_for_ip_address | bool |
|
|
wait_for_ip_address_timeout | interger |
|
|
wait_for_customization_timeout | interger |
|
|
wait_for_customization | bool |
|
|
state_change_timeout | interger |
|
|
snapshot_src | string | |
|
linked_clone | bool |
|
|
force | bool |
|
|
delete_from_inventory | bool |
|
|
datacenter | string |
|
|
cluster | string | |
|
esxi_hostname | string | |
|
advanced_settings | list | |
|
annotation | string | |
|
customvalues | list | |
|
networks | list | |
|
customization | dict | |
|
vaap_properties | list/dict | |
|
customization_spec | string | |
|
datastore | string | |
|
convert | string |
|
|
Este módulo utiliza fragmentos da documentação do módulo VMware Options.
Sub-options de hardware
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
hotadd_cpu | bool | | Permitir que CPUs virtuais sejam adicionadas enquanto a máquina virtual está em execução |
hotremove_cpu | bool | | Permitir que as CPUs virtuais sejam removidas enquanto a máquina virtual estiver em execução |
hotadd_memory | bool | | Permitir que a memória seja adicionada enquanto a máquina virtual está em execução |
memory_mb | interger | | Quantidade de memória em MB |
num_cpus | interger | |
|
num_cpu_cores_per_socket | interger | | Número de núcleos por soquete |
scsi | string |
|
|
secure_boot | bool | | Se deve ativar ou desativar a inicialização segura (U)EFI |
memory_reservation_lock | bool | | Se definido C(true), reserva de recurso de memória para a máquina virtual |
max_connections | interger | | Número máximo de conexões de exibição remota ativas para as máquinas virtuais |
mem_limit | interger | |
|
mem_reservation | interger | | A quantidade de recurso de memória garantidamente disponível para a máquina virtual |
cpu_limit | interger | |
|
cpu_reservation | interger | | A quantidade de recursos da CPU garantidamente disponível para a máquina virtual |
version | string | |
|
boot_firmware | string |
| Escolha qual firmware deve ser usado para inicializar a máquina virtual |
nested_virt | bool | | Habilitar virtualização aninhada |
virt_based_security | bool | |
|
iommu | bool | | Sinalizador para especificar se I/O MMU está ativado para esta máquina virtual |
Sub-options de disk
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
size | string |
| Tamanho de armazenamento do disco na unidade especificada. Se size especificado, a unidade deve ser especificada. Não há espaço permitido entre o número do tamanho e a unidade. Apenas a primeira ocorrência no elemento de disco será considerada, mesmo se houver vários parâmetros de tamanho * disponíveis. |
size_kb | interger | | Tamanho do armazenamento do disco em kb |
size_mb | bool | | Tamanho do armazenamento do disco em mb |
size_gb | interger | | Tamanho do armazenamento do disco em gb |
size_tb | interger | | Tamanho do armazenamento do disco em tb |
type | interger |
|
|
datastore | string | |
|
filename | string | |
|
autoselect_datastore | bool | |
|
disk_mode | string |
| Número máximo de conexões de exibição remota ativas para as máquinas virtuais |
controller_type | string |
|
|
controller_number | interger |
|
|
unit_number | interger | |
|
Sub-options de nvdimn
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
state | string |
|
|
size_mb | interger | | Tamanho do dispositivo NVDIMM virtual em MB |
label | string | |
|
Sub-options de cdrom
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
type | string | |
|
iso_path | interger | |
|
controller_type | string | |
|
controller_number | interger | |
|
unit_number | interger | |
|
state | string | |
|
Sub-options de networks
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
name | string | |
|
vlan | interger | |
|
device_type | string | |
|
mac | string | |
|
dvswitch | string | |
|
dvswitch_name | string | |
|
type | string | |
|
ip | string | |
|
netmask | string | |
|
gateway | string | |
|
dns_servers | string | |
|
domain | string | |
|
connected | bool | |
|
start_connected | bool | |
|
Sub-options de customization
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
existing_vm | bool | |
|
dns_servers | list/string | |
|
dns_suffix | list/string | |
|
domain | string | |
|
hostname | string | |
|
timezone | string | |
|
hwclockUTC | bool | |
|
autologon | bool | |
|
autologonaccount | interger | |
|
domainadmin | string | |
|
domainadminpassword | string | |
|
fullname | string | |
|
joindomain | string | |
|
joinworkgroup | string | |
|
orgname | string | |
|
password | string | |
|
productid | string | |
|
runonce | list/string | |
|
Sub-options de vaap_properties
Parâmetro | Tipo | Escolhas | Valor Padrão | Comentários |
|---|---|---|---|
id | string | |
|
value | string | |
|
type | string | |
|
operation | string | |
|
Notas
Observação
- Testado em vSphere 7.0.2
- Todos os módulos requerem acesso de gravação API e, portanto, não são suportados em uma licença ESXi gratuita.
- Por exemplo, a seguir está a lista de privilégios mínimos exigidos pelos usuários para criar máquinas virtuais.
- DataStore > Alocar Espaço
- 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
Exemplos
- name: Create a virtual machine on given ESXi hostname
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
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_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
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\ConfigureRemotingForAtmosphere.ps1 -ForceNewSSLCert -EnableCredSSP
delegate_to: localhost
- name: Clone a virtual machine from Linux template and customize
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
delegate_to: localhost
- name: Rename a virtual machine (requires the virtual machine's uuid)
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
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
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
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
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
uuid: "{{ vm_uuid }}"
state: poweredoff
delegate_to: localhost
- name: Deploy a virtual machine in a datastore different from the datastore of the template
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ vm_name }}"
state: present
template: "{{ template_name }}"
# Here datastore can be different which holds template
datastore: "{{ virtual_machine_datastore }}"
hardware:
memory_mb: 512
num_cpus: 2
scsi: paravirtual
delegate_to: localhost
- name: Create a diskless VM
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}"
state: poweredoff
cluster: "{{ ccr1 }}"
name: diskless_vm
folder: /Asia-Datacenter1/vm
guest_id: centos64Guest
datastore: "{{ ds1 }}"
hardware:
memory_mb: 1024
num_cpus: 2
num_cpu_cores_per_socket: 1
- name: Create a VM with multiple disks of different disk controller types
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: /DC1/vm/
name: test_vm_multi_disks
state: poweredoff
guest_id: centos64Guest
datastore: datastore1
disk:
- size_gb: 10
controller_type: 'nvme'
controller_number: 0
unit_number: 0
- size_gb: 10
controller_type: 'paravirtual'
controller_number: 0
unit_number: 1
- size_gb: 10
controller_type: 'sata'
controller_number: 0
unit_number: 2
hardware:
memory_mb: 512
num_cpus: 4
version: 14
networks:
- name: VM Network
device_type: vmxnet3
delegate_to: localhost
register: deploy_vm
- name: Create a VM with NVDIMM device
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: /DC1/vm/
name: test_vm_nvdimm
state: poweredoff
guest_id: centos7_64Guest
datastore: datastore1
hardware:
memory_mb: 512
num_cpus: 4
version: 14
networks:
- name: VM Network
device_type: vmxnet3
nvdimm:
state: present
size_mb: 2048
delegate_to: localhost
register: deploy_vm
Valores Retornados
Chave | Tipo | Retornado quando | Descrição |
|---|---|---|---|
instance | dictionary | sempre | metadados sobre a máquina virtual |