infra/roles/pve/tasks/destroy_vm.yml
2019-05-25 15:05:52 +04:00

35 lines
873 B
YAML

- set_fact: node_name="{{tmp_node}}"
- set_fact: vm_name="{{node_name}}.{{stack.name}}"
- name: checking that vm exists
proxmox_kvm:
node: srv
api_user: "{{env.pve.username}}"
api_password: "{{env.pve.password}}"
api_host: "{{env.pve.api_url}}"
name: "{{vm_name}}"
state: current
ignore_errors: true
register: vm_exists
- block:
- name: stopping vm
proxmox_kvm:
node: srv
api_user: "{{env.pve.username}}"
api_password: "{{env.pve.password}}"
api_host: "{{env.pve.api_url}}"
name: "{{vm_name}}"
state: stopped
force: yes
timeout: 120
- name: destroying vm
proxmox_kvm:
node: srv
api_user: "{{env.pve.username}}"
api_password: "{{env.pve.password}}"
api_host: "{{env.pve.api_url}}"
name: "{{vm_name}}"
state: absent
when: vm_exists is succeeded