Skip to content

Commit 1419963

Browse files
authored
Merge pull request #19 from stackhpc/os_images_merge
os_images role
2 parents 54a9148 + 3cb4e56 commit 1419963

File tree

11 files changed

+633
-0
lines changed

11 files changed

+633
-0
lines changed

roles/os_images/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
OpenStack Images
2+
================
3+
4+
This role generates guest instance images using disk-image-builder
5+
and uploads them to OpenStack using the `openstack.cloud.image` module.
6+
7+
Requirements
8+
------------
9+
10+
The OpenStack APIs should be accessible from the target host.
11+
Client credentials should have been set in the environment, or
12+
using the `clouds.yaml` format.
13+
14+
You must use a virtualenv with system site packages enabled
15+
as this role relies on python packages installed by the package
16+
manager, e.g:
17+
18+
```
19+
virtualenv --system-site-packages ~/venvs/dib
20+
```
21+
22+
Role Variables
23+
--------------
24+
25+
`os_images_package_dependencies_extra`: List of additional packages to install
26+
on the build host.
27+
28+
`os_images_cache`: a path to a directory in which to cache build artefacts.
29+
It defaults to `~/disk_images`
30+
`NOTE`: new images will NOT be built, even if changes are made in config, if an image is already cached.
31+
Use `force_rebuild` flag in order to apply new config changes.
32+
33+
`os_images_auth_type`: OpenStack authentication endpoint and credentials.
34+
Defaults to `password`.
35+
36+
`os_images_auth`: OpenStack authentication endpoint and credentials. For
37+
example, a dict of the form:
38+
* `auth_url`: Keystone auth endpoint URL. Defaults to `OS_AUTH_URL`.
39+
* `project`: OpenStack tenant/project. Defaults to `OS_TENANT_NAME`.
40+
* `username`: OpenStack username. Defaults to `OS_USERNAME`.
41+
* `password`: OpenStack password. Defaults to `OS_PASSWORD`.
42+
43+
`os_images_region`: Define a region to upload the images. Default is None.
44+
45+
`os_images_cacert` is an optional path to a CA certificate bundle.
46+
47+
`os_images_interface` is the endpoint URL type to fetch from the service
48+
catalog. Maybe be one of `public`, `admin`, or `internal`.
49+
50+
`os_images_list` is a list of YAML dicts, where `elements` and `image_url` are
51+
mutually exclusive where each contain:
52+
* `name`: the image name to use in OpenStack.
53+
* `elements`: a list of diskimage-builder elements to incorporate into the image.
54+
* `image_url`: the URL to image location on the Internet.
55+
* `checksum`: Checksum to validate a downloaded image. Format: <algorithm>:<checksum|url>.
56+
* `env`: (optional) environment variables to define for diskimage-builder parameters.
57+
This is a dict of the form of `KEY: VALUE`.
58+
* `packages`: (optional) list of packages to install in the image.
59+
* `size`: (optional) size to make the image filesystem.
60+
* `properties`: (optional) dict of properties to set on the glance image.
61+
Common image properties are available
62+
[here](https://docs.openstack.org/glance/latest/user/common-image-properties.html).
63+
* `type`: (optional) image type. Default in DIB is qcow2. Image formats are
64+
available [here](https://docs.openstack.org/glance/latest/user/formats.html).
65+
* `force_rebuild`: (optional) boolean flag indicating whether or not the image should always
66+
be built (even if an existing image that name has been built before). The images on glance
67+
will be replaced if `os_images_upload` is set to `True`. This defaults to
68+
`os_images_force_rebuild`if left unset.
69+
* `is_public`: (optional) whether the image should be set as visible to all
70+
projects or kept private.
71+
* `owner`: (optional) ID of the project that should own the uploaded image.
72+
73+
`os_images_common`: A set of elements to include in every image listed.
74+
Defaults to `cloud-init enable-serial-console stable-interface-names`.
75+
76+
`os_images_dib_pkg_name`: Optionally customise the name parameter passed
77+
to the ansible.builtin.pip module when installing diskimage-builder. This can
78+
be used to install diskimage-builder from version control.
79+
80+
`os_images_dib_version`: Optionally set a version of diskimage-builder to install.
81+
By default this is not constrained.
82+
83+
`os_images_git_elements`: An optional list of elements to pull from github, deploy
84+
locally for incorporation into the images. Supply a list of dicts with the
85+
following parameters:
86+
* `repo`: URL to a git repo for cloning (if not already present)
87+
* `local`: local path for git cloning
88+
* `version`: optional git reference (branch, tag, hash) for cloning. Defaults
89+
to `HEAD`
90+
* `elements_path`: optional relative path to elements within the repository.
91+
92+
`os_images_elements`: An optional list of paths for site-specific DIB elements.
93+
94+
`os_images_upload`: Whether to upload built images to Glance. Defaults to `True`.
95+
96+
`os_images_force_rebuild`: Whether or not to force a rebuild of the DIB image. The images on Glance
97+
will be replaced with the newly built image if `os_images_upload` is set to `True`. Defaults to
98+
`False`.
99+
100+
`os_images_public`: Whether uploaded images are public. Defaults to `True` - note this requires admin permissions.
101+
102+
`os_images_venv`: Path to virtualenv in which to install python dependencies to upload images.
103+
104+
`os_images_dib_venv`: Path to virtualenv in which to install DIB to build images.
105+
106+
`os_images_promote`: Whether or not to retire old and promote new images. Defaults to `False`.
107+
108+
`os_images_build`: Whether or not to build the images.
109+
110+
`os_images_name_suffix`: Image suffix which would be removed during image promotion, for exmple: -rc, -dev, -test etc. Mandatory for promotion functionality. Empty by default.
111+
112+
`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`.
113+
114+
Dependencies
115+
------------
116+
117+
Example Playbook
118+
----------------
119+
120+
The following playbook generates a guest image and uploads it to OpenStack:
121+
122+
---
123+
- name: Generate guest image and upload
124+
hosts: localhost
125+
roles:
126+
- role: stackhpc.openstack.os_images
127+
os_images_auth:
128+
auth_url: "{{ lookup('env','OS_AUTH_URL') }}"
129+
username: "{{ lookup('env','OS_USERNAME') }}"
130+
password: "{{ lookup('env','OS_PASSWORD') }}"
131+
project_name: "{{ lookup('env','OS_TENANT_NAME') }}"
132+
os_images_list:
133+
- name: FedoraCore
134+
elements:
135+
- fedora
136+
- selinux-permissive
137+
- alaska-extras
138+
env:
139+
DIB_ALASKA_DELETE_REPO: "y"
140+
DIB_ALASKA_PKGLIST: "pam-python pam-keystone"
141+
- name: FedoraAtomic27
142+
image_url: https://ftp.icm.edu.pl/pub/Linux/dist/fedora-alt/atomic/stable/Fedora-Atomic-27-20180326.1/CloudImages/x86_64/images/Fedora-Atomic-27-20180326.1.x86_64.qcow2
143+
properties:
144+
os_distro: fedora-atomic
145+
type: qcow2
146+
147+
Author Information
148+
------------------
149+
150+
- Stig Telfer (<[email protected]>)

roles/os_images/defaults/main.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
# List of additional host package dependencies to install.
3+
os_images_package_dependencies_extra: []
4+
# Path to virtualenv in which to install python dependencies to upload images.
5+
os_images_venv:
6+
# Path to virtualenv in which to install DIB to build images.
7+
os_images_dib_venv: "{{ os_images_venv }}"
8+
9+
# State of python dependencies.
10+
os_images_package_state: present
11+
12+
# Upper constraints file for installation of python dependencies to upload
13+
# images.
14+
#
15+
# Use Antelope upper constraints as openstacksdk 1.0.1 and openstackclient 6.2.0 are required
16+
os_images_upper_constraints_file: https://releases.openstack.org/constraints/upper/2023.1
17+
18+
# Upper constraints file for installation of DIB to build images.
19+
os_images_dib_upper_constraints_file: ""
20+
21+
# Path to a directory in which to cache build artefacts.
22+
os_images_cache: "{{ lookup('env', 'HOME') }}/disk_images"
23+
24+
# List of paths of site-specific diskimage-builder elements
25+
# os_images_elements: [ "{{ playbook_dir }}/stackhpc-image-elements" ]
26+
os_images_elements: []
27+
# Common elements to include in all images
28+
os_images_common: cloud-init enable-serial-console stable-interface-names
29+
30+
# Example image definition:
31+
# os_images_list:
32+
# - name: CentOS7-OFED4
33+
# elements:
34+
# - centos7
35+
# - mlnx-ofed
36+
# size: 3GB
37+
# properties:
38+
# os_distro: centos
39+
# env:
40+
# DIB_XXX: yyy
41+
# packages:
42+
# - biosdevname
43+
# type: qcow2
44+
# - name: FedoraAtomic27
45+
# image_url: https://ftp.icm.edu.pl/pub/Linux/dist/fedora-alt/atomic/stable/Fedora-Atomic-27-20180326.1/CloudImages/x86_64/images/Fedora-Atomic-27-20180326.1.x86_64.qcow2
46+
# properties:
47+
# os_distro: fedora-atomic
48+
# type: qcow2
49+
os_images_list: []
50+
# Common properties to apply to all glance images.
51+
os_images_common_properties:
52+
cpu_arch: x86_64
53+
54+
# OpenStack authentication type: passed to the os_image Ansible module
55+
os_images_auth_type: password
56+
57+
# OpenStack authentication credentials:
58+
# For example, take OpenStack authentication credentials from the environment
59+
# os_images_auth:
60+
# auth_url: "{{ lookup('env','OS_AUTH_URL') }}"
61+
# username: "{{ lookup('env','OS_USERNAME') }}"
62+
# password: "{{ lookup('env','OS_PASSWORD') }}"
63+
# project_name: "{{ lookup('env','OS_TENANT_NAME') }}"
64+
os_images_auth:
65+
# Endpoint URL type to fetch from the service catalog. Maybe be one of:
66+
# public, admin, or internal.
67+
os_images_interface:
68+
# Default region for OpenStack endpoint.
69+
os_images_region:
70+
# Pin to a specific version of diskimage-builder if required
71+
os_images_dib_version:
72+
# Customise the name parameter passed to the ansible.builtin.pip module.
73+
os_images_dib_pkg_name: diskimage-builder
74+
75+
# List of git repositories containing site-specific diskimage-builder elements.
76+
# Each item should be a dict containing 'repo', 'local', and optionally,
77+
# 'version' items.
78+
os_images_git_elements: []
79+
# Whether to upload built images to Glance.
80+
os_images_upload: true
81+
82+
# Whether or not the images should be rebuilt if they already exist
83+
os_images_force_rebuild: false
84+
85+
# Whether images should be public (requires admin rights)
86+
os_images_public: true
87+
88+
# Whether or not should old images be retired and new images be promoted
89+
os_images_promote: false
90+
91+
# Whether or not to build the images
92+
os_images_build: true
93+
94+
# Image suffix which would be removed during image promotion for exmple: -rc, -dev, -test
95+
os_images_name_suffix:
96+
# Whether or not to hide the images in Glance list
97+
os_images_hide: false

roles/os_images/meta/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
dependencies:
3+
- role: stackhpc.openstack.os_openstacksdk
4+
os_openstacksdk_venv: "{{ os_images_venv }}"
5+
os_openstacksdk_state: "{{ os_images_package_state }}"
6+
os_openstacksdk_upper_constraints_file: "{{ os_images_upper_constraints_file }}"
7+
8+
- role: stackhpc.openstack.os_openstackclient
9+
os_openstackclient_venv: "{{ os_images_venv }}"
10+
os_openstackclient_state: "{{ os_images_package_state }}"
11+
os_openstackclient_upper_constraints_file: "{{ os_images_upper_constraints_file }}"

0 commit comments

Comments
 (0)