--- - hosts: localhost gather_facts: no tasks: - name: ensure libraries are available import_role: name: lib_utils - name: set expire date set_fact: sas_expire: "{{ lookup('pipe', 'date -d \"14 days\" +\"%Y-%m-%dT%H:%M:00Z\"') }}" disk: "{{ image_name }}.vhd" - name: fetch the image for the tags command: | az image list --resource-group images -o json --query "[?name=='{{ image_name }}'].tags" register: imagetags - name: generate storage blob url command: | az storage blob url -c {{ openshift_azure_container }} --account-name {{ openshift_azure_storage_account }} -n {{ disk }} --output=json register: bloburl - name: generate sas url for the container command: | az storage container generate-sas --name {{ openshift_azure_container }} --account-name {{ openshift_azure_storage_account }} --permissions rl --expiry {{ sas_expire }} --output=json register: sasurl - name: set the sas URLS set_fact: openshift_azure_sas_url: "{{ bloburl.stdout|from_json + '?' + sasurl.stdout|from_json }}" - name: set the image tags set_fact: image_tags: "{{ (imagetags.stdout | from_json)[0] }}" - name: set the image_type set_fact: image_type: "{{ 'rhel' if 'rhel' in image_tags.base_image else 'centos' }}" image_vm_images: |- { "{{ image_tags.openshift | regex_search('([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})') }}": {"osVhdUrl": "{{ openshift_azure_sas_url }}" } } - name: fetch the current offer and update the versions oo_azure_rm_publish_image_facts: offer: "{{ azure_image_publish[image_type].offer }}" register: offerout - when: - offerout['status_code'] != 404 block: - debug: msg: "{{ offerout }}" verbosity: 1 - debug: msg: "{{ offerout['data']['definition']['plans'][0]['microsoft-azure-virtualmachines.vmImages'] }}" verbosity: 1 - debug: msg: "{{ lookup('template', 'offer.yml.j2') }}" verbosity: 1 - name: bring along the previous offer versions and combine with incoming yedit: content: "{{ lookup('template', 'offer.yml.j2') }}" key: "definition#plans[0]#microsoft-azure-virtualmachines.vmImages#{{ item.key }}" value: "{{ item.value }}" separator: '#' with_dict: "{{ offerout['data']['definition']['plans'][0]['microsoft-azure-virtualmachines.vmImages'] }}" when: - "'data' in offerout" - "'definition' in offerout['data']" register: yeditout - debug: msg: "{{ yeditout }}" verbosity: 1 # this cancel operation returns a 202 whether it cancelled or not. - name: cancel publish operation oo_azure_rm_publish_image: offer: "{{ azure_image_publish[image_type].offer }}" state: cancel_op - name: create|update an offer in cloudpartner portal oo_azure_rm_publish_image: offer: "{{ azure_image_publish[image_type].offer }}" offer_data: "{{ (lookup('template', 'offer.yml.j2') | from_yaml) if 'skipped' in yeditout and yeditout.skipped or not yeditout.changed else yeditout.results[0].result[0].edit }}" force: True - name: publish this offer oo_azure_rm_publish_image: state: publish offer: "{{ azure_image_publish[image_type].offer }}" emails: "{{ openshift_azure_image_publish_emails }}"