vmware.vmware_rest icon indicating copy to clipboard operation
vmware.vmware_rest copied to clipboard

RFE: vmware.vmware_rest.vcenter_vm support power_on for created VMs

Open Tronde opened this issue 1 year ago • 1 comments

SUMMARY

The docs at [0] describe the parameter power_on to "Attempt to perform a {@link #powerOn} after clone."

I guess this parameter only works when state: clone, because it doesn't work when state: present. I would like to have this module support the parameter for state: present as well to be able to power on newly created VMs without using an additional task.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

vcenter_vm.py

ADDITIONAL INFORMATION

The feature would be use to create and power on the created VM in one task. So it would be ease to use a dict with multiple VMs to have them created and powered on without using the vcenter_vm_power module on each VM afterwards.

---
- name: Gather vSphere information and create VM
  hosts: localhost
  vars_files:
    - my.vault
  debugger: on_failed

  tasks:
    - name: Create a VM
      vmware.vmware_rest.vcenter_vm:
        vcenter_hostname: "{{ vmware_host }}"
        vcenter_username: "{{ vmware_user }}"
        vcenter_password: "{{ vmware_pass }}"
        vcenter_validate_certs: false
        placement:
          cluster: "{{ resource_pool_info.id }}"
          datastore: "{{ my_datastore.datastore }}"
          folder: "{{ my_vm_folder.folder }}"
          resource_pool: "{{ resource_pool_info.value.resource_pool }}"
        name: VM1
        guest_OS: RHEL_8_64
        hardware_version: VMX_19
        boot:
          type: BIOS
        cdroms:
        - allow_guest_control: true
          backing:
            type: "ISO_FILE"
            iso_file: "{{ MY_ISO_PATH }}"
          label: "CD/DVD drive 1"
          start_connected: true
        cpu:
          count: 2
        memory:
          hot_add_enabled: true
          size_MiB: 2048
        disks:
        - type: SCSI
          new_vmdk:
            name: vm1
            capacity: 2000000
            storage_policy: 
              policy: "{{ MY_POLICY }}"
        nics:
        - start_connected: true
          type: VMXNET3
          mac_type: GENERATED
          backing:
              type: STANDARD_PORTGROUP
              network: "{{ my_network.network }}"
        state: present
        power_on: true
      register: _result

But in _result if found "power_state": "POWERED_OFF", afterwards.

[0] https://docs.ansible.com/ansible/latest/collections/vmware/vmware_rest/vcenter_vm_module.html#parameters

In case you need additional information to understand the use case, please, don't hesitate to ask and I try to explain it in more detail.

Tronde avatar Apr 12 '23 12:04 Tronde