Skip to content

Commit

Permalink
Attempt to limit loop execution when instance is created successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
Stringy committed Jun 5, 2024
1 parent acc800b commit 9a2e54a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ansible/roles/create-vm/tasks/create-s390x-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
- ibm_output_inventory_file != ""
delegate_to: localhost

- set_fact:
instance_created: true

rescue:
- name: Check if VSI was created
ibm.cloudcollection.ibm_is_instance_info:
Expand Down
7 changes: 4 additions & 3 deletions ansible/roles/create-vm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
excluded: "{{ vm_image in excluded_vms }}"
when: vm_image is defined and excluded == false

- set_fact:
instance_created: false

- block:
- name: Create IBM Z VM
include_tasks: create-s390x-vm.yml
vars:
vsi_name: "{{ vm_name }}"
vsi_zone: "{{ zone.name }}"
vsi_subnet_id: "{{ zone.subnet_id }}"
condition: "{{ (instance_result | default({'changed': false })).changed }}"
when: vm_arch == "s390x" and not condition
when: vm_arch == "s390x" and not instance_created
loop: "{{ s390x.zones }}"
loop_control:
loop_var: zone
register: instance_result

- name: Create IBM POWER VM
include_tasks: create-ppc64le-vm.yml
Expand Down

0 comments on commit 9a2e54a

Please sign in to comment.