From 6b4f180a1ef286cce13a64a7718a38148ffa3ece Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Thu, 14 Nov 2019 13:43:58 +0000
Subject: [PATCH] Support installing packages in IPA images

Diskimage builder supports specifying a list of packages to install via
-p. We currently support this for the root image, but not IPA images.

This change adds a new configuration option, 'ipa_build_dib_packages',
that should be a list of additional packages to install in locally built
IPA images. This affects the following commands:

kayobe seed deployment image build
kayobe overcloud deployment image build

This depends on
https://github.com/stackhpc/ansible-role-os-images/pull/25.

Also adds an example to the documentation for the equivalent option for
root image.

Change-Id: I04191d9541894b6a264e966c9ecb1056e0edade4
Story: 2006855
Task: 37446
---
 ansible/group_vars/all/ipa                       |  3 +++
 ansible/overcloud-ipa-build.yml                  |  1 +
 ansible/seed-ipa-build.yml                       |  1 +
 doc/source/configuration/bifrost.rst             | 14 ++++++++++++++
 doc/source/configuration/ironic-python-agent.rst | 16 ++++++++++++++++
 etc/kayobe/ipa.yml                               |  3 +++
 .../ipa-build-dib-packages-5e85baba3294eb65.yaml |  6 ++++++
 requirements.yml                                 |  2 +-
 8 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/ipa-build-dib-packages-5e85baba3294eb65.yaml

diff --git a/ansible/group_vars/all/ipa b/ansible/group_vars/all/ipa
index 3d422849..d17cac11 100644
--- a/ansible/group_vars/all/ipa
+++ b/ansible/group_vars/all/ipa
@@ -56,6 +56,9 @@ ipa_build_dib_env: >
 # stackhpc.os-images role for usage.
 ipa_build_dib_git_elements: []
 
+# List of DIB packages to install. Default is none.
+ipa_build_dib_packages: []
+
 ###############################################################################
 # Ironic Python Agent (IPA) images configuration.
 
diff --git a/ansible/overcloud-ipa-build.yml b/ansible/overcloud-ipa-build.yml
index 3b7a5139..aa3c1994 100644
--- a/ansible/overcloud-ipa-build.yml
+++ b/ansible/overcloud-ipa-build.yml
@@ -36,6 +36,7 @@
               - name: "{{ ipa_image_name }}"
                 elements: "{{ ipa_build_dib_elements }}"
                 env: "{{ ipa_build_dib_env }}"
+                packages: "{{ ipa_build_dib_packages }}"
                 # Avoid needing to install qemu-img for qcow2 image.
                 type: raw
             os_images_git_elements: "{{ ipa_build_dib_git_elements }}"
diff --git a/ansible/seed-ipa-build.yml b/ansible/seed-ipa-build.yml
index f1afb808..1e2e0e41 100644
--- a/ansible/seed-ipa-build.yml
+++ b/ansible/seed-ipa-build.yml
@@ -27,6 +27,7 @@
               - name: "{{ ipa_image_name }}"
                 elements: "{{ ipa_build_dib_elements }}"
                 env: "{{ ipa_build_dib_env }}"
+                packages: "{{ ipa_build_dib_packages }}"
                 # Avoid needing to install qemu-img for qcow2 image.
                 type: raw
             os_images_git_elements: "{{ ipa_build_dib_git_elements }}"
diff --git a/doc/source/configuration/bifrost.rst b/doc/source/configuration/bifrost.rst
index c24b2e50..a8673a71 100644
--- a/doc/source/configuration/bifrost.rst
+++ b/doc/source/configuration/bifrost.rst
@@ -167,6 +167,20 @@ Alternatively, the :diskimage-builder-doc:`dynamic-login element
 <elements/dynamic-login/README>` can be used to authorize SSH keys by appending
 them to the kernel arguments.
 
+Example: Installing a package
+-----------------------------
+
+It can be necessary to install additional packages in the root disk image.
+Rather than needing to write a custom DIB element, we can use the
+``kolla_bifrost_dib_packages`` variable. For example, to install the
+``biosdevname`` package:
+
+.. code-block:: yaml
+   :caption: ``ipa.yml``
+
+   kolla_bifrost_dib_packages:
+     - "biosdevname"
+
 Ironic configuration
 ====================
 
diff --git a/doc/source/configuration/ironic-python-agent.rst b/doc/source/configuration/ironic-python-agent.rst
index 74c8c4ce..c79b9418 100644
--- a/doc/source/configuration/ironic-python-agent.rst
+++ b/doc/source/configuration/ironic-python-agent.rst
@@ -66,6 +66,8 @@ image build``.
     List of git repositories containing Diskimage Builder (DIB) elements. See
     `stackhpc.os-images <https://galaxy.ansible.com/stackhpc/os-images>`__ role
     for usage. Default is none.
+``ipa_build_dib_packages``
+    List of DIB packages to install. Default is none.
 
 Example: Building IPA images locally
 ------------------------------------
@@ -156,6 +158,20 @@ In this example the ``master`` branch of
 https://git.example.com/custom-dib-elements would have a top level ``elements``
 directory, containing a ``my-element`` directory for the element.
 
+Example: Installing a package
+-----------------------------
+
+It can be necessary to install additional packages in the IPA image. Rather
+than needing to write a custom DIB element, we can use the
+``ipa_build_dib_packages`` variable. For example, to install the
+``biosdevname`` package:
+
+.. code-block:: yaml
+   :caption: ``ipa.yml``
+
+   ipa_build_dib_packages:
+     - "biosdevname"
+
 Ironic Python Agent (IPA) images configuration
 ==============================================
 
diff --git a/etc/kayobe/ipa.yml b/etc/kayobe/ipa.yml
index 63b0499d..e91ac57a 100644
--- a/etc/kayobe/ipa.yml
+++ b/etc/kayobe/ipa.yml
@@ -47,6 +47,9 @@
 # stackhpc.os-images role for usage.
 #ipa_build_dib_git_elements:
 
+# List of DIB packages to install. Default is none.
+#ipa_build_dib_packages:
+
 ###############################################################################
 # Ironic Python Agent (IPA) images configuration.
 
diff --git a/releasenotes/notes/ipa-build-dib-packages-5e85baba3294eb65.yaml b/releasenotes/notes/ipa-build-dib-packages-5e85baba3294eb65.yaml
new file mode 100644
index 00000000..02ef4ea3
--- /dev/null
+++ b/releasenotes/notes/ipa-build-dib-packages-5e85baba3294eb65.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Adds support for installing packages in locally built Ironic Python Agent
+    (IPA) images via the ``ipa_build_dib_packages`` variable. See `story
+    2006855 <https://storyboard.openstack.org/#!/story/2006855>`__ for details.
diff --git a/requirements.yml b/requirements.yml
index fc75de49..5b2d7642 100644
--- a/requirements.yml
+++ b/requirements.yml
@@ -30,7 +30,7 @@
 - src: stackhpc.mellanox-switch
   version: v1.0.0
 - src: stackhpc.os-images
-  version: v1.4.0
+  version: v1.6.0
 - src: stackhpc.os-ironic-state
   version: v1.1.0
 - src: stackhpc.os-networks
-- 
GitLab