SF initial configurator | a26c41e | 2022-10-06 13:33:13 +0300 | [diff] [blame] | 1 | --- |
| 2 | - assert: |
| 3 | that: |
| 4 | - image_url is defined |
| 5 | - image_checksum is defined |
| 6 | - image is defined |
| 7 | - image_url != '' |
| 8 | - image_checksum != '' |
| 9 | - image != '' |
| 10 | |
| 11 | - name: Set some runtime facts |
| 12 | set_fact: |
| 13 | image_cache_file: "{{ image_cache_dir }}/{{ image }}" |
| 14 | image_tmp_dir: "/var/tmp/{{ image_output | basename }}" |
| 15 | |
| 16 | - name: Make sure cache directory exist |
| 17 | file: |
| 18 | path: "{{ image_cache_dir }}" |
| 19 | state: directory |
| 20 | |
| 21 | - name: Delete previous image cache |
| 22 | file: |
| 23 | path: "{{ image_cache_file }}" |
| 24 | state: absent |
| 25 | when: image_wipe_cache |
| 26 | |
| 27 | - name: Check if image is already downloaded |
| 28 | stat: |
| 29 | path: "{{ image_cache_file }}" |
| 30 | register: _image_cache_file_stat |
| 31 | |
| 32 | - name: Download if checksum doesn't match |
| 33 | get_url: |
| 34 | url: "{{ image_url }}" |
| 35 | dest: "{{ image_cache_file }}" |
| 36 | checksum: "{{ image_checksum }}" |
| 37 | when: not _image_cache_file_stat.stat.exists |
| 38 | |
| 39 | - name: Extract the image if necessary |
| 40 | command: "xz -k -d {{ image_cache_file }}.xz" |
| 41 | args: |
| 42 | chdir: "{{ image_cache_dir }}" |
| 43 | creates: "{{ image_cache_file }}" |
| 44 | |
| 45 | - name: Update the cache |
| 46 | command: "virt-customize -m {{ memsize }} -a {{ image_cache_file }} --update" |
| 47 | environment: "{{ virt_customize_env|default({}) }}" |
| 48 | |
| 49 | - name: Create tmp directory |
| 50 | file: |
| 51 | path: "{{ image_tmp_dir }}" |
| 52 | state: directory |
| 53 | mode: '0755' |
| 54 | |
| 55 | - name: Set filename copy fact |
| 56 | set_fact: |
| 57 | image_file: "{{ image_tmp_dir }}/{{ image_cache_file | basename }}" |
| 58 | |
| 59 | - name: Copy the image |
| 60 | copy: |
| 61 | src: "{{ image_cache_file }}" |
| 62 | dest: "{{ image_file }}" |
| 63 | remote_src: true |
| 64 | mode: '0644' |
| 65 | |
| 66 | - set_fact: |
| 67 | virt_customize_cmd: |
| 68 | - "virt-customize -m {{ memsize }} -a {{ image_file }}" |
| 69 | - "--selinux-relabel" |
| 70 | - "--install '{{ base_packages | join(',') }}'" |