ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
818 stars 1.5k forks source link

proxmox_kvm - state:stopped forced:yes - rather use STOP that SHUTDOWN #1906

Open hvisage opened 3 years ago

hvisage commented 3 years ago

Summary

The use of shutdown, when it states "STOPped" is quite unexpected, especially with a force:yes. I would be expecting that state:shutdown would run through the "normal" shutdown process, while state:stopped issued a STOP command to the VM via the API.

Issue Type

Bug Report

Component Name

proxmox_kvm

Ansible Version

ansible 2.10.5
  config file = /home/hvisage/Projects/ad-infra/ansible/ansible.cfg
  configured module search path = ['/home/hvisage/Projects/ad-infra/ansible/ansible/playbooks/library', '/home/hvisage/Projects/ad-infra/ansible/ansible/plugins/library', '/home/hvisage/Projects/ad-infra/ansible/ansible/library', '/home/hvisage/Projects/ad-infra/ansible/debops/ansible/playbooks/playbooks/library', '/home/hvisage/Projects/ad-infra/ansible/debops/ansible/playbooks/library', '/home/hvisage/Projects/ad-infra/ansible/debops/ansible/plugins/library', '/home/hvisage/Projects/ad-infra/ansible/debops/ansible/library', '/home/hvisage/.local/share/debops/debops/ansible/playbooks/playbooks/library', '/home/hvisage/.local/share/debops/debops/ansible/playbooks/library', '/home/hvisage/.local/share/debops/debops/ansible/plugins/library', '/home/hvisage/.local/share/debops/debops/ansible/library', '/home/hvisage/debops/lib/python3.7/site-packages/debops/ansible/plugins/library', '/home/hvisage/debops/lib/python3.7/site-packages/debops/ansible/playbooks/library', '/home/hvisage/.local/share/debops/debops/ansible/playbooks/library', '/usr/share/ansible/library']
  ansible python module location = /home/hvisage/debops/lib/python3.7/site-packages/ansible
  executable location = /home/hvisage/debops/bin/ansible
  python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]

Configuration

playbook:

---
- hosts: localhost
  tasks:

    - name: lets kill them
      proxmox_kvm:
        api_user: 'root@pam'
        api_token_id: 'adtest'
        api_token_secret : 'secrets'
        api_host: 'FQDN.net'
        state: stopped
        timeout: 30
        vmid: '{{ item }}'
        force: yes
      loop: [ 366810, 366820 ]

    - name: lets delete them
      proxmox_kvm:
        api_user: 'root@pam'
        api_token_id: 'adtest'
        api_token_secret : 'secrets'
        api_host: 'FQDN.net'
        state: absent
        vmid: '{{ item }}'
        force: yes
      loop: [ 366810, 366820 ]

    - name: Mendix VM
      proxmox_kvm:
        name: AGW-AD-lacm01-mx
        api_user: 'root@pam'
        api_token_id: 'adtest'
        api_token_secret : 'secrets'
        api_host: 'FQDN.net'
        clone: deb10-8tmpl
        vmid: 99995
        newid: 366810
        node: targetnode
        storage: local-zfs
        format: raw
        timeout: 300
        cores: 4
        memory: 4096
        sockets: 1
        net:
          net0: 'virtio,bridge=vmbr0,tag=3668,mac=c0:ff:ee:0e:54:0a'
        virtio:
          virtio1: 'local-zfs:10'
        pool: 'PoolName1'

    - name: DB VM
      proxmox_kvm:
        name: AGW-AD-lacm01-db
        api_user: 'root@pam'
        api_token_id: 'adtest'
        api_token_secret : 'secrets'
        api_host: 'FQDN.net'
        clone: arbitrary_name
        vmid: 99995
        newid: 366820
        node: targetnode
        storage: local-zfs
        format: raw
        timeout: 300
        cores: 4
        memory: 4096
        sockets: 1
        net:
          net0: 'virtio,bridge=vmbr0,tag=3668,mac=c0:ff:ee:0e:54:14'
        virtio:
          virtio1: 'local-zfs:10'
          virtio2: 'local-zfs:20'
        pool: 'PoolName1'

    - name: Start them engines!
      proxmox_kvm:
        api_user: 'root@pam'
        api_token_id: 'adtest'
        api_token_secret : 'secrets'
        api_host: 'FQDN.net'
        state: started
        vmid: '{{ item }}'
      loop:
        - 366810
        - 366820

OS / Environment

Debian 10.8 netinst.iso installed template, no guest agent installed yet.

Proxmox VM Settings: QEMU Guest Agent Enabled

Steps To Reproduce


create a Debian 10.8 template from netinst.iso  - don't isntall the QEMU guest agent
make sure the template's option that QEMU Guest Agent is enabled
run the create_vm playbook to create and start the VMs. 
rerun to attempt to delete the running VMs

Expected Results

VMs to be STOPped (not shutdown attempted)

Actual Results

TASK [lets kill them] ********************************************************************************************************************************************
[DEPRECATION WARNING]: The proxmox_default_behavior option will change its default value from "compatibility" to "no_defaults" in community.general 4.0.0. To
remove this warning, please specify an explicit value for it now. This feature will be removed from community.general in version 4.0.0. Deprecation warnings can
be disabled by setting deprecation_warnings=False in ansible.cfg.
failed: [localhost] (item=366810) => changed=false
  ansible_loop_var: item
  item: 366810
  msg: 'Reached timeout while waiting for stopping VM. Last line in task before timeout: [{''n'': 1, ''t'': ''trying to acquire lock...''}]'
failed: [localhost] (item=366820) => changed=false
  ansible_loop_var: item
  item: 366820
  msg: 'Reached timeout while waiting for stopping VM. Last line in task before timeout: [{''n'': 1, ''t'': ''trying to acquire lock...''}]'

When you have VMs that might take long, or have other problems that have the boot process stuck (ie. having supervisor, nfs, systemd and supervisor starting processes on the nfs mounts as a good example that I'm struggling with) or don't "see" the shutdown request (ie. the example I'm now presented with where the QEMU agent isn't loaded, or something else stopped it, and the VM settings is set for QEMU guest agent isntalled), the use of shutdown is futile, and the need for STOP is necessary.

Would a pull request to change STOPped to se stop and state:shutdown to be added , be accepted?

ansibullbot commented 3 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 3 years ago

cc @Aversiste @Thulium-Drake @helldorado @joshainglis @karmab click here for bot help

ansibullbot commented 3 years ago

cc @Ajpantuso click here for bot help

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

PC-Admin commented 1 year ago

This is behavior I'd also like to see fixed. There should be a new value for state called 'shutdown' or something for when you actually want to do a shutdown. Not being able to simply stop a VM with this module is frustrating really.

ansibullbot commented 1 year ago

cc @UnderGreen click here for bot help

UnderGreen commented 1 year ago

@PC-Admin, @hvisage would force shutdown with timeout work for you?

hvisage commented 1 year ago

How would the workflow be? (I don't recall a forced shutdown in Proxmox) what has to be remembered, is when you have soething like the guest agent setting "on, and the guest agent isn't running - for whatever reason, a shutdown/reboot send via proxmox to the Qemu/VM, will take an extraordinary long time before that task times out. Thus to "force" it with a timeout on the Ansible side, you'll have to first CANCEL the task, and once cancelled, clear any related locks that might still be hanging around, before you go to the forced reset/stop

On 06 Jun 2023, at 03:46, Sergei Antipov @.***> wrote:

@PC-Admin, @hvisage would force shutdown with timeout work for you? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

herzkerl commented 1 year ago

After running into that same 'issue' I think this clarification might help:

ansibullbot commented 7 months ago

cc @krauthosting click here for bot help