|
| 1 | +- debug: |
| 2 | + msg: | |
| 3 | + terraform_backend_type: {{ terraform_backend_type }} |
| 4 | + terraform_state: {{ terraform_state }} |
| 5 | + cluster_upgrade_system_packages: {{ cluster_upgrade_system_packages | default('undefined') }} |
| 6 | +
|
| 7 | +# We need to convert the floating IP id to an address for Terraform |
| 8 | +# if we we have cluster_floating_ip, otherwise assume that we're |
| 9 | +# assigning the FIP in Terraform and that it will be available in |
| 10 | +# outputs.cluster_gateway_ip. |
| 11 | +- block: |
| 12 | + - name: Look up floating IP |
| 13 | + include_role: |
| 14 | + name: stackhpc.terraform.infra |
| 15 | + tasks_from: lookup_floating_ip |
| 16 | + vars: |
| 17 | + os_floating_ip_id: "{{ cluster_floating_ip }}" |
| 18 | + |
| 19 | + - name: Set floating IP address fact |
| 20 | + set_fact: |
| 21 | + cluster_floating_ip_address: "{{ os_floating_ip_info.floating_ip_address }}" |
| 22 | + when: cluster_floating_ip is defined |
| 23 | + |
| 24 | +- name: Install Terraform binary |
| 25 | + include_role: |
| 26 | + name: stackhpc.terraform.install |
| 27 | + |
| 28 | +- name: Make Terraform project directory |
| 29 | + file: |
| 30 | + path: "{{ terraform_project_path }}" |
| 31 | + state: directory |
| 32 | + |
| 33 | +- name: Write backend configuration |
| 34 | + copy: |
| 35 | + content: | |
| 36 | + terraform { |
| 37 | + backend "{{ terraform_backend_type }}" { } |
| 38 | + } |
| 39 | + dest: "{{ terraform_project_path }}/backend.tf" |
| 40 | + |
| 41 | +# Patching in this appliance is implemented as a switch to a new base image |
| 42 | +# So unless explicitly patching, we want to use the same image as last time |
| 43 | +# To do this, we query the previous Terraform state before updating |
| 44 | +- block: |
| 45 | + - name: Get previous Terraform state |
| 46 | + stackhpc.terraform.terraform_output: |
| 47 | + binary_path: "{{ terraform_binary_path }}" |
| 48 | + project_path: "{{ terraform_project_path }}" |
| 49 | + backend_config: "{{ terraform_backend_config }}" |
| 50 | + register: cluster_infra_terraform_output |
| 51 | + |
| 52 | + - name: Extract image from Terraform state |
| 53 | + set_fact: |
| 54 | + cluster_previous_image: "{{ cluster_infra_terraform_output.outputs.cluster_image.value }}" |
| 55 | + when: '"cluster_image" in cluster_infra_terraform_output.outputs' |
| 56 | + when: |
| 57 | + - terraform_state == "present" |
| 58 | + - cluster_upgrade_system_packages is not defined or not cluster_upgrade_system_packages |
| 59 | + |
| 60 | +- name: Detect volume device prefix from image metadata |
| 61 | + block: |
| 62 | + - name: Get image metadata from OpenStack API |
| 63 | + openstack.cloud.image_info: |
| 64 | + image: "{{ cluster_previous_image | default(cluster_image) }}" |
| 65 | + register: cluster_image_info |
| 66 | + - name: Check only single image found |
| 67 | + assert: |
| 68 | + that: cluster_image_info.images | length == 1 |
| 69 | + fail_msg: "Multiple images found for 'cluster_image' {{ cluster_image }}" |
| 70 | + - name: Set volume_device_prefix fact |
| 71 | + set_fact: |
| 72 | + block_device_prefix: >- |
| 73 | + {{ |
| 74 | + 'sd' if (cluster_image_info.images | first).hw_scsi_model is defined and |
| 75 | + (cluster_image_info.images | first).hw_scsi_model in scsi_models |
| 76 | + else 'vd' |
| 77 | + }} |
| 78 | + # Only run when block_device_prefix isn't set as an extravar |
| 79 | + when: |
| 80 | + - block_device_prefix is not defined |
| 81 | + - cluster_image is defined |
| 82 | + |
| 83 | +- name: Template Terraform files into project directory |
| 84 | + template: |
| 85 | + src: >- |
| 86 | + {{ |
| 87 | + "{}{}.j2".format( |
| 88 | + ( |
| 89 | + cluster_terraform_template_dir ~ "/" |
| 90 | + if cluster_terraform_template_dir is defined |
| 91 | + else "" |
| 92 | + ), |
| 93 | + item |
| 94 | + ) |
| 95 | + }} |
| 96 | + dest: "{{ terraform_project_path }}/{{ item }}" |
| 97 | + loop: |
| 98 | + - outputs.tf |
| 99 | + - providers.tf |
| 100 | + - resources.tf |
| 101 | + |
| 102 | +- name: Provision infrastructure |
| 103 | + include_role: |
| 104 | + name: stackhpc.terraform.infra |
0 commit comments