Ansible VMWare 不干净的数据存储

Ansible VMWare not clean datastore

我编写了 2 个 Ansible 剧本来创建和销毁 ESXi 实例中的虚拟机。

创建任务是:

- name: Clone the template
  delegate_to: localhost
  community.vmware.vmware_guest:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    cluster: "{{ vcenter_cluster_name }}"
    datacenter: "{{ vcenter_datacenter_name }}"
    folder: "{{ vcenter_datacenter_folder }}"
    datastore: "{{ vcenter_datastore }}"
    validate_certs: False
    name: "{{ inventory_hostname }}"
    template: "{{ vm_template }}"
    state: poweredon
    wait_for_ip_address: yes
    networks:
      - name: "DSwitch_Dati-VM Network 869"
        ip: "{{ ansible_host }}"
        netmask: "{{ vm_netmask }}"
        gateway: "{{ vm_gateway }}"
        start_connected: yes

删除剧本是:

- name: TMS Cleaner
  hosts: all
  remote_user: tms
  tasks:
    - name: Set powerstate of virtual machine to poweroff
      delegate_to: localhost
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: False
        name: "{{ inventory_hostname }}"
        state: poweredoff

    - name: Remove virtual machine from inventory
      delegate_to: localhost
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        folder: "{{ vcenter_datacenter_folder }}"
        datastore: "{{ vcenter_datastore }}"
        validate_certs: False
        name: "{{ inventory_hostname }}"
        delete_from_inventory: True
        state: absent

创建是正确的,而删除可以正确地停止和删除 vm,但它不会从数据存储中删除文件夹。

我应该怎么做才能完全删除与虚拟机相关的所有文件?

如果您还想从 datastore 中删除文件,您需要删除以下行:

delete_from_inventory: True

this module 的 ansible 文档说:

delete_from_inventory:

选择:是从清单中删除虚拟机还是从磁盘中删除。 没有 |是的

仅删除该行,文件将从数据存储中删除。