|
1 | 1 | --- |
2 | 2 | - name: Include OS family-specific variables |
3 | | - include_vars: "{{ ansible_facts.os_family }}.yml" |
4 | | - |
| 3 | + ansible.builtin.include_vars: "{{ ansible_facts.os_family }}.yml" |
5 | 4 | - name: Ensure required packages are installed |
6 | | - package: |
| 5 | + ansible.builtin.package: |
7 | 6 | name: "{{ (os_images_package_dependencies + os_images_package_dependencies_extra) | select | list }}" |
8 | 7 | state: present |
9 | 8 | become: true |
|
12 | 11 | - name: Ensure diskimage-builder SELinux dependencies are installed |
13 | 12 | vars: |
14 | 13 | package_name: "{{ 'policycoreutils-python' if ansible_facts.distribution_major_version | int == 7 else 'python3-policycoreutils' }}" |
15 | | - package: |
| 14 | + ansible.builtin.package: |
16 | 15 | name: "{{ package_name }}" |
17 | 16 | state: present |
18 | 17 | when: |
|
22 | 21 | become: true |
23 | 22 |
|
24 | 23 | - name: Ensure download cache dir exists |
25 | | - file: |
| 24 | + ansible.builtin.file: |
26 | 25 | path: "{{ os_images_cache }}" |
27 | 26 | owner: "{{ ansible_facts.user_uid }}" |
28 | 27 | group: "{{ ansible_facts.user_gid }}" |
29 | 28 | state: directory |
30 | 29 | become: true |
31 | 30 |
|
32 | 31 | - name: Remove old images for force rebuild |
33 | | - file: |
| 32 | + ansible.builtin.file: |
34 | 33 | path: "{{ os_images_cache }}/{{ item.name }}" |
35 | 34 | state: absent |
36 | 35 | when: item.force_rebuild | default(os_images_force_rebuild) | bool |
|
40 | 39 | tags: clean |
41 | 40 |
|
42 | 41 | - name: Generate per-image cache directories |
43 | | - file: |
| 42 | + ansible.builtin.file: |
44 | 43 | path: "{{ os_images_cache }}/{{ item.name }}" |
45 | 44 | owner: "{{ ansible_facts.user_uid }}" |
46 | 45 | group: "{{ ansible_facts.user_gid }}" |
|
50 | 49 | label: "{{ item.name }}" |
51 | 50 | become: true |
52 | 51 |
|
53 | | -- block: |
| 52 | +- vars: |
| 53 | + image_dest: "{{ os_images_cache }}/{{ item.name }}/{{ item.name }}.{{ item.type | default('qcow2') }}{{ '.xz' if image_is_xz else '' }}" |
| 54 | + image_is_xz: "{{ item.image_url.endswith('.xz') }}" |
| 55 | + when: item.image_url is defined |
| 56 | + |
| 57 | + block: |
54 | 58 | - name: Download the image to the directory when an image_url is defined |
55 | | - get_url: |
| 59 | + ansible.builtin.get_url: |
56 | 60 | url: "{{ item.image_url }}" |
57 | 61 | dest: "{{ image_dest }}" |
58 | 62 | checksum: "{{ item.checksum | default(omit) }}" |
59 | 63 | with_items: "{{ os_images_list | list }}" |
60 | 64 | loop_control: |
61 | 65 | label: "{{ item.name }}" |
62 | 66 | - name: Unpack the image if .xz format |
63 | | - command: unxz --keep --force {{ image_dest }} |
| 67 | + ansible.builtin.command: unxz --keep --force {{ image_dest }} |
64 | 68 | when: image_is_xz |
65 | 69 | with_items: "{{ os_images_list | list }}" |
66 | 70 | loop_control: |
67 | 71 | label: "{{ item.name }}" |
68 | | - vars: |
69 | | - image_dest: "{{ os_images_cache }}/{{ item.name }}/{{ item.name }}.{{ item.type | default('qcow2') }}{{ '.xz' if image_is_xz else '' }}" |
70 | | - image_is_xz: "{{ item.image_url.endswith('.xz') }}" |
71 | | - when: item.image_url is defined |
72 | | - |
73 | 72 | - name: Install a suitable version of diskimage-builder |
74 | | - pip: |
| 73 | + ansible.builtin.pip: |
75 | 74 | name: "{{ item.name }}" |
76 | 75 | version: "{{ item.version or omit }}" |
77 | 76 | state: "{{ os_images_package_state }}" |
|
82 | 81 | version: "{{ os_images_dib_version }}" |
83 | 82 |
|
84 | 83 | - name: Git clone any additional image element repos |
85 | | - git: |
| 84 | + ansible.builtin.git: |
86 | 85 | repo: "{{ item.repo }}" |
87 | 86 | dest: "{{ item.local }}" |
88 | 87 | version: "{{ item.version | default('HEAD') }}" |
89 | 88 | with_items: "{{ os_images_git_elements }}" |
90 | 89 |
|
91 | 90 | - name: Set a fact containing paths to DIB elements |
92 | | - set_fact: |
| 91 | + ansible.builtin.set_fact: |
93 | 92 | os_images_elements_path: "{{ os_images_elements }}" |
94 | 93 |
|
95 | 94 | - name: Incorporate git-sourced DIB elements |
96 | | - set_fact: |
| 95 | + ansible.builtin.set_fact: |
97 | 96 | os_images_elements_path: > |
98 | 97 | {{ os_images_elements_path + |
99 | 98 | [item.local ~ '/' ~ item.elements_path] }} |
100 | 99 | with_items: "{{ os_images_git_elements }}" |
101 | 100 | when: item.elements_path is defined |
102 | 101 |
|
103 | 102 | - name: Set a fact containing the default DIB environment |
104 | | - set_fact: |
| 103 | + ansible.builtin.set_fact: |
105 | 104 | os_image_dib_env_default: |
106 | 105 | ELEMENTS_PATH: "{{ os_images_elements_path | join(':') }}" |
107 | 106 |
|
108 | 107 | - name: Generate diskimage-builder images |
109 | 108 | vars: |
110 | 109 | dib_args: >- |
111 | | - {% if item.size is defined %}--image-size {{ item.size }}{% endif %} |
112 | | - {% if item.type is defined %}-t {{ item.type }}{% endif %} |
113 | | - {% if item.packages | default %}-p {{ item.packages | join(',') }}{% endif %} |
114 | | - {{ os_images_common }} |
115 | | - {{ item.elements | join( ' ' ) }} |
116 | | - -o {{ item.name }} |
117 | | - shell: . {{ os_images_dib_venv }}/bin/activate && disk-image-create {{ dib_args }} > {{ item.name }}.stdout 2> {{ item.name }}.stderr |
| 110 | + {% if item.size is defined %}--image-size {{ item.size }}{% endif %} {% if item.type is defined %}-t {{ item.type }}{% endif %} {% if item.packages | default |
| 111 | + %}-p {{ item.packages | join(',') }}{% endif %} {{ os_images_common }} {{ item.elements | join(' ') }} -o {{ item.name }} |
| 112 | + ansible.builtin.shell: . {{ os_images_dib_venv }}/bin/activate && disk-image-create {{ dib_args }} > {{ item.name }}.stdout 2> {{ item.name }}.stderr |
118 | 113 | args: |
119 | 114 | chdir: "{{ os_images_cache }}/{{ item.name }}" |
120 | 115 | creates: "{{ os_images_cache }}/{{ item.name }}/{{ item.name }}.d/dib-manifests" |
|
129 | 124 | when: item.elements is defined |
130 | 125 |
|
131 | 126 | - name: Fail if any images failed to build |
132 | | - fail: |
| 127 | + ansible.builtin.fail: |
133 | 128 | msg: > |
134 | 129 | Image {{ item.0.name }} failed to build. See |
135 | 130 | {{ item.0.name }}.stdout and {{ item.0.name }}.stderr in |
|
0 commit comments