Skip to content

VM power state not working #7

@domendobnikar

Description

@domendobnikar

There is an issue where vm power state is sometimes not set correctly to start, when certain fields are being set/changed like number of CPUs.

Sample playbook/task:

- name: retail-edge workload deployment playbook
  hosts: region1
  connection: ansible.builtin.local
  gather_facts: False
  tasks:
  # - name: Get cluster VM info
  #   scale_computing.hypercore.vm_info:
  #     cluster_instance:
  #       host: "https://{{inventory_hostname}}"
  #       username: "{{scale_user}}"
  #       password: "{{scale_pass}}"
  #   register: vm_info

  # - name: output the vm_info request results
  #   debug:
  #     var: vm_info   
      
  - name: ubuntu20_04 template - Ubuntu 20.04 - import if not present
    scale_computing.hypercore.vm_import:
      cluster_instance:
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: ubuntu20_04
      smb:
        server: "{{smbserver}}"
        path: "{{smbpath}}"
        username: "{{smbusername}}"
        password: "{{smbpassword}}"
#    ignore_errors: yes
    register: ubuntu20_04

  - name: protect ubuntu20_04 template from powering on
    scale_computing.hypercore.vm:
      cluster_instance:
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: ubuntu20_04      
      memory: "{{ '1 GB'|human_to_bytes}}"
      description: "{{inventory_hostname}}"
      tags:
        - ansible
        - template
        - demo
      vcpu: 1 # filed issue that this can't be set to zero here
      state: present
      power_state: stop
      disks:
      - type: virtio_disk
        disk_slot: 0
        size: "{{ '200 GB' | human_to_bytes }}"
      nics:
      - vlan: 0
        type: virtio
      # boot_devices:
      # - type: virtio_disk
      #  disk_slot: 0      
#could set node affinity to no nodes as well

  - name: clone vm demo1 - if not present
    scale_computing.hypercore.vm_clone:
      cluster_instance:   # question - is there a way to define this once per playbook vs. every task?
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: demo1
      tags:
        - demo
        - ansible
      source_vm_name: ubuntu20_04
      cloud_init:
        user_data: |
          #cloud-config
          apt_update: true
          apt_upgrade: true
          password: "{{scale_pass}}"
          chpasswd: { expire: False }
          ssh_pwauth: True
        meta_data: |
          dsmode: local
          network-interfaces: |
            auto lo
            iface lo inet loopback 
            iface ens3 inet static
              address 192.168.1.200
              netmask 255.255.255.0
              gateway 192.168.1.1
              dns-nameservers 8.8.8.8
          local-hostname: demo1 

#one issue to address - the cloud init clone above attaches an iso image with the cloud init info ... named first 8 char of vm uuid.iso ... not sure how to keep that attached when starting below?

  - name: clone vm demo2 - if not present
    scale_computing.hypercore.vm_clone:
      cluster_instance:
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: demo2
      tags:
        - demo
        - ansible      
      source_vm_name: ubuntu20_04
      cloud_init:
        user_data: |
          #cloud-config
          apt_update: true
          apt_upgrade: true
          password: "{{scale_pass}}"
          chpasswd: { expire: False }
          ssh_pwauth: True
        meta_data: |
          dsmode: local
          network-interfaces: |
            auto lo
            iface lo inet loopback 
            iface ens3 inet static
              address 192.168.1.201
              netmask 255.255.255.0
              gateway 192.168.1.1
              dns-nameservers 8.8.8.8
          local-hostname: demo2
    
  - name: verify vm demo1 desired configuration  
    scale_computing.hypercore.vm:
      cluster_instance:
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: demo1
      memory: "{{ '1 GB'|human_to_bytes}}"
      description: "{{inventory_hostname}}"
      vcpu: 2
      state: present
      power_state: start   #possible bug - right now the VM doesn't start first time this playbook executes ... it makes some config changes but doesn't start - if you run again it starts
      disks:
      # - type: ide_cdrom  #see comment above - how do I get the cloud init iso with correct name to attach before starting?
      #   disk_slot: 0
      #   iso_name: cloud-init-3534544e.iso
      - type: virtio_disk
        disk_slot: 0
        size: "{{ '200 GB' | human_to_bytes }}"
      nics:
      - vlan: 0
        type: virtio
      boot_devices:
      - type: virtio_disk
        disk_slot: 0

  - name: verify vm demo2 desired configuration
    scale_computing.hypercore.vm:
      cluster_instance:
        host: "https://{{inventory_hostname}}"
        username: "{{scale_user}}"
        password: "{{scale_pass}}"
      vm_name: demo2
      memory: "{{ '1 GB'|human_to_bytes}}"
      description: "{{inventory_hostname}}"
      vcpu: 2
      state: present
      power_state: start
      disks:
      - type: virtio_disk
        disk_slot: 0
        size: "{{ '200 GB' | human_to_bytes }}"
      nics:
      - vlan: 0
        type: virtio
      boot_devices:
      - type: virtio_disk
        disk_slot: 0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions