Skip to content

Commit

Permalink
Delete in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
betoredhat committed Feb 9, 2024
1 parent 11f8126 commit b3ad0b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 0 additions & 5 deletions roles/kvirt_vm/tasks/create-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
pod-security.kubernetes.io/enforce: "baseline"
pod-security.kubernetes.io/enforce-version: "latest"

- name: Delete VM {{ vm.name }}
ansible.builtin.include_tasks: delete-vm.yml
when:
- vm.force | default(kvirt_vm_force) | bool

- name: Create the VM {{ vm.name }}
community.kubernetes.k8s:
definition: "{{ lookup('template', 'templates/vm-template.yml.j2') }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/kvirt_vm/tasks/delete-vm.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Delete VM {{ name }}"
- name: "Delete VM {{ vm.name }}"
community.kubernetes.k8s:
kind: VirtualMachine
api_version: "{{ vm.api_version | default(kvirt_vm_api_version) }}"
Expand Down
10 changes: 9 additions & 1 deletion roles/kvirt_vm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
- name: Run validations
ansible.builtin.include_tasks: validations.yml

- name: "Create the VM"
- name: Delete VM
ansible.builtin.include_tasks: delete-vm.yml
when: vm.force | default(kvirt_vm_force) | bool
loop: "{{ vm_configs }}"
loop_control:
loop_var: vm
label: "{{ vm.name }}"

- name: Create the VM
ansible.builtin.include_tasks: create-vm.yml
loop: "{{ vm_configs }}"
loop_control:
Expand Down

0 comments on commit b3ad0b0

Please sign in to comment.