From 20942f0c514243c150e018871b2e415ed5670e8f Mon Sep 17 00:00:00 2001 From: Olivier Valentin Date: Fri, 20 Mar 2026 09:33:52 +0100 Subject: [PATCH] Use vpc_inventory to retrieve Z VMs - no more inventory file generation - VMs have tags similar to what is done in GCP --- ansible/ci/inventory_IBM-Z.vpc.yml | 17 +++++++++ ansible/dev/inventory_IBM-Z.vpc.yml | 1 + .../roles/create-vm/tasks/create-s390x-vm.yml | 35 +++---------------- 3 files changed, 23 insertions(+), 30 deletions(-) create mode 100644 ansible/ci/inventory_IBM-Z.vpc.yml create mode 120000 ansible/dev/inventory_IBM-Z.vpc.yml diff --git a/ansible/ci/inventory_IBM-Z.vpc.yml b/ansible/ci/inventory_IBM-Z.vpc.yml new file mode 100644 index 0000000000..f1b3d51744 --- /dev/null +++ b/ansible/ci/inventory_IBM-Z.vpc.yml @@ -0,0 +1,17 @@ +--- +plugin: ibm.cloudcollection.vpc_inventory +regions: + - us-east +#ibmcloud_api_key: "{{ lookup('env', 'IBM_CLOUD_S390X_API_KEY') }}" +ansible_host_type: name +fail_on_duplicate: false +compose: + ibm_cloud_vm: "true" + vm_arch: "tags | select('match', '^vm_arch:') | map('split', ':') | map('last') | first" + vm_config: "tags | select('match', '^vm_config:') | map('split', ':') | map('last') | first" + vm_image_family: "tags | select('match', '^vm_image_family:') | map('split', ':') | map('last') | first" +filters: + resource_group: 1a33a6a9bd6e498f8115e9b1064bfa97 +keyed_groups: + - key: "tags | select('match', '^job_id:') | map('split', ':') | map('last') | first" + prefix: job_id diff --git a/ansible/dev/inventory_IBM-Z.vpc.yml b/ansible/dev/inventory_IBM-Z.vpc.yml new file mode 120000 index 0000000000..ab9effd946 --- /dev/null +++ b/ansible/dev/inventory_IBM-Z.vpc.yml @@ -0,0 +1 @@ +../ci/inventory_IBM-Z.vpc.yml \ No newline at end of file diff --git a/ansible/roles/create-vm/tasks/create-s390x-vm.yml b/ansible/roles/create-vm/tasks/create-s390x-vm.yml index d5452aa5c0..010e731f83 100644 --- a/ansible/roles/create-vm/tasks/create-s390x-vm.yml +++ b/ansible/roles/create-vm/tasks/create-s390x-vm.yml @@ -28,6 +28,11 @@ zone: "{{ s390x.zone }}" boot_volume: - size: "{{ s390x.disk_size }}" + tags: + - "job_id:{{ job_id }}" + - "vm_config:{{ vm_config }}" + - "vm_image_family:{{ vm_family }}" + - "vm_arch:{{ vm_arch }}" register: vsi - name: Check for existing Floating IP @@ -51,33 +56,3 @@ debug: msg: "{{ vsi_name }} IP Address: {{ fip.resource.address }}" - always: - # regardless of success/failure of VM creation we want to add an entry - # to the inventory. VM creation can fail but a VM can be created (in a failed - # state) but without a record of it in the inventory we can leak VM instances - # in IBM cloud. Empty defaults in some variables here are to account for this. - - name: Add VSI to Ansible inventory - add_host: - name: "{{ vsi_name }}" - ansible_user: root - ansible_host: "{{ fip.resource.address | default('') }}" - groups: - - job_id_{{ job_id }} - - platform_{{ test_platform }} - - vm_arch_s390x - ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" - ansible_ssh_private_key_file: "{{ vm_ssh_key_file }}" - vm_config: "{{ vm_config }}" - vm_image_family: "{{ vm_family }}" - vm_collection_method: "{{ vm_collection_method }}" - vm_arch: "{{ vm_arch }}" - ibm_cloud_vm: true - - - name: generate provisioner inventory file - template: - src: 'ibm-cloud-inventory.j2' - dest: "{{ ibm_output_inventory_file }}" - mode: '0644' - when: - - ibm_output_inventory_file != "" - delegate_to: localhost