Skip to content
35 changes: 35 additions & 0 deletions roles/os_images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ mutually exclusive where each contain:
This is a dict of the form of `KEY: VALUE`.
* `packages`: (optional) list of packages to install in the image.
* `size`: (optional) size to make the image filesystem.
* `architecture`: (optional) image CPU architecture to pass to diskimage-builder `-a`.
If unset, default to the diskimage-builder default architecture: `x86_64`, and upload
Glance images with the `cpu_arch: "x86_64"` image property.
When setting, consider also setting `properties.cpu_arch` to a corresponding value.
* `properties`: (optional) dict of properties to set on the glance image.
Common image properties are available
[here](https://docs.openstack.org/glance/latest/user/common-image-properties.html).
Expand All @@ -76,6 +80,9 @@ or 'community'. Default is 'public'
`os_images_common`: A set of elements to include in every image listed.
Defaults to `cloud-init enable-serial-console stable-interface-names`.

`os_images_common_properties`: A dict of Glance image properties to set on all images.
Defaults to an empty dict, and is overridden by `os_images_list.*.properties`.

`os_images_dib_pkg_name`: Optionally customise the name parameter passed
to the ansible.builtin.pip module when installing diskimage-builder. This can
be used to install diskimage-builder from version control.
Expand Down Expand Up @@ -118,6 +125,34 @@ will be replaced with the newly built image if `os_images_upload` is set to `Tru

`os_images_hide`: Whether or not to hide the images in Glance list. Hiding images is available as an option in image retirement/promotion process. Defaults to `False`.

Changing platform architecture in os_images
-------------------------------------------

The target CPU architecture for each image defined in `os_images_list` may be set to any architecture supported by diskimage-builder with the `architecture` parameter.

If it is unset, an image with the default diskimage-builder architecture (`x86_64`) will be built and optionally uploaded to Glance, with the Glance image property `cpu_arch` set to `x86_64`.

If `architecture` is set for an image, consider also setting `properties.cpu_arch` to an architecture [supported by Glance](https://docs.openstack.org/glance/latest/admin/useful-image-properties.html#image-property-keys-and-values). An example is given below.

```yaml
os_images_list:
- name: ubuntu
elements:
- ubuntu
packages:
- biosdevname
type: qcow2
- name: ubuntu-aarch64
architecture: arm64
elements:
- ubuntu
properties:
cpu_arch: aarch64
packages:
- biosdevname
type: qcow2
```

Dependencies
------------

Expand Down
3 changes: 1 addition & 2 deletions roles/os_images/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ os_images_common: cloud-init enable-serial-console stable-interface-names
# type: qcow2
os_images_list: []
# Common properties to apply to all glance images.
os_images_common_properties:
cpu_arch: x86_64
os_images_common_properties: {}

# OpenStack authentication type: passed to the os_image Ansible module
os_images_auth_type: password
Expand Down
5 changes: 3 additions & 2 deletions roles/os_images/tasks/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
- name: Generate diskimage-builder images
vars:
dib_args: >-
{% if item.size is defined %}--image-size {{ item.size }}{% endif %} {% if item.type is defined %}-t {{ item.type }}{% endif %} {% if item.packages | default
%}-p {{ item.packages | join(',') }}{% endif %} {{ os_images_common }} {{ item.elements | join(' ') }} -o {{ item.name }}
{% if item.size is defined %}--image-size {{ item.size }}{% endif %} {% if item.type is defined %}-t {{ item.type }}{% endif %}
{% if item.packages | default %}-p {{ item.packages | join(',') }}{% endif %} {{ os_images_common }} {{ item.elements | join(' ') }}
-o {{ item.name }} {% if item.architecture is defined %}-a {{ item.architecture }}{% endif %}
ansible.builtin.shell: . {{ os_images_dib_venv }}/bin/activate && disk-image-create {{ dib_args }} > {{ item.name }}.stdout 2> {{ item.name }}.stderr
args:
chdir: "{{ os_images_cache }}/{{ item.name }}"
Expand Down
11 changes: 10 additions & 1 deletion roles/os_images/tasks/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,19 @@
container_format: bare
disk_format: "{{ item.0.type | default('qcow2') }}"
filename: "{{ os_images_cache }}/{{ item.0.name }}/{{ item.0.name }}.{{ item.0.type | default('qcow2') }}"
properties: "{{ os_images_common_properties | combine(item.0.properties | default({})) or omit }}"
properties: "{{ os_images_common_properties | combine(cpu_arch_properties) | combine(item.0.properties | default({})) or omit }}"
kernel: "{{ item.1.id if is_baremetal else omit }}"
ramdisk: "{{ item.2.id if is_baremetal else omit }}"
vars:
# NOTE(m-anson): When architecture isn't defined for an
# image, assume that we should set cpu_arch: x86_64 as
# this is the diskimage-builder default.
cpu_arch_properties: >-
{{
{}
if item.0.architecture is defined
else {"cpu_arch": "x86_64"}
}}
is_baremetal: "{{ item.0.elements is defined and 'baremetal' in item.0.elements }}"
visibility: "{{ item.0.visibility | default(item.0.is_public | ternary('public', 'private') if item.0.is_public is defined else os_images_visibility) }}"
with_together:
Expand Down