From d6aa4ea16e917996d6009956b4edcd1ed4275c72 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Wed, 21 Apr 2021 12:18:11 +0100
Subject: [PATCH] Ubuntu: simplify OS distro selection

Adds a new 'os_distribution' variable which can be used to select the OS
distribution, with sensible defaults for other variables. The default
value is 'centos'.

This patch changes the default value for the '*_bootstrap_user'
variables from using the $USER environment variable to using fixed
defaults equal to the os_distribution variable. This aligns with the
standard user configured in most cloud images, and images created via
DIB.

Note that we are continuing to use a CentOS based IPA image, since we
have been unable to get IPA to build for Ubuntu.

Depends-On: https://review.opendev.org/c/openstack/kayobe-config-dev/+/788234

Change-Id: I9e10239f58fe209867116fa2e10f1ce74220b966
Story: 2004960
Task: 42323
---
 ansible/group_vars/all/bifrost                  | 17 ++++++++++-------
 ansible/group_vars/all/compute                  |  4 ++--
 ansible/group_vars/all/controllers              |  4 ++--
 ansible/group_vars/all/globals                  |  7 +++++++
 ansible/group_vars/all/kolla                    |  5 +++--
 ansible/group_vars/all/seed                     |  4 ++--
 ansible/group_vars/all/seed-hypervisor          |  4 ++--
 ansible/group_vars/all/seed-vm                  | 13 +++++++++++--
 ansible/group_vars/all/storage                  |  4 ++--
 etc/kayobe/bifrost.yml                          |  8 +++++---
 etc/kayobe/compute.yml                          |  2 +-
 etc/kayobe/controllers.yml                      |  2 +-
 etc/kayobe/globals.yml                          |  7 +++++++
 etc/kayobe/kolla.yml                            |  3 ++-
 etc/kayobe/seed-hypervisor.yml                  |  2 +-
 etc/kayobe/seed-vm.yml                          |  3 +++
 etc/kayobe/seed.yml                             |  2 +-
 etc/kayobe/storage.yml                          |  2 +-
 .../notes/os-distribution-69445eb19a611d43.yaml | 14 ++++++++++++++
 19 files changed, 77 insertions(+), 30 deletions(-)
 create mode 100644 releasenotes/notes/os-distribution-69445eb19a611d43.yaml

diff --git a/ansible/group_vars/all/bifrost b/ansible/group_vars/all/bifrost
index 81224ed1..d26c9c86 100644
--- a/ansible/group_vars/all/bifrost
+++ b/ansible/group_vars/all/bifrost
@@ -18,15 +18,18 @@ kolla_bifrost_firewalld_internal_zone: trusted
 ###############################################################################
 # Diskimage-builder configuration.
 
-# DIB base OS element.
-kolla_bifrost_dib_os_element: "centos"
+# DIB base OS element. Default is {{ os_distribution }}.
+kolla_bifrost_dib_os_element: "{{ os_distribution }}"
 
-# DIB image OS release.
-kolla_bifrost_dib_os_release: "8"
+# DIB image OS release. Default is "focal" when os_distribution is "ubuntu", or
+# "8" otherwise.
+kolla_bifrost_dib_os_release: "{{ 'focal' if os_distribution == 'ubuntu' else '8' }}"
 
-# List of default DIB elements.
+# List of default DIB elements. Default is ["disable-selinux",
+# "enable-serial-console", "vm"] when os_distribution is "centos", or
+# ["enable-serial-console", "vm"] otherwise.
 kolla_bifrost_dib_elements_default:
-  - "disable-selinux"
+  - "{% if os_distribution == 'centos' %}disable-selinux{% endif %}"
   - "enable-serial-console"
   - "vm"
 
@@ -34,7 +37,7 @@ kolla_bifrost_dib_elements_default:
 kolla_bifrost_dib_elements_extra: []
 
 # List of all DIB elements.
-kolla_bifrost_dib_elements: "{{ kolla_bifrost_dib_elements_default + kolla_bifrost_dib_elements_extra }}"
+kolla_bifrost_dib_elements: "{{ kolla_bifrost_dib_elements_default | select | list + kolla_bifrost_dib_elements_extra }}"
 
 # DIB init element.
 kolla_bifrost_dib_init_element: "cloud-init-datasources"
diff --git a/ansible/group_vars/all/compute b/ansible/group_vars/all/compute
index eb5f7bd9..61bbe91f 100644
--- a/ansible/group_vars/all/compute
+++ b/ansible/group_vars/all/compute
@@ -3,8 +3,8 @@
 # Compute node configuration.
 
 # User with which to access the computes via SSH during bootstrap, in order
-# to setup the Kayobe user account.
-compute_bootstrap_user: "{{ lookup('env', 'USER') }}"
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
+compute_bootstrap_user: "{{ os_distribution }}"
 
 ###############################################################################
 # Compute network interface configuration.
diff --git a/ansible/group_vars/all/controllers b/ansible/group_vars/all/controllers
index e820bcf1..0c09024f 100644
--- a/ansible/group_vars/all/controllers
+++ b/ansible/group_vars/all/controllers
@@ -3,8 +3,8 @@
 # Controller node configuration.
 
 # User with which to access the controllers via SSH during bootstrap, in order
-# to setup the Kayobe user account.
-controller_bootstrap_user: "{{ lookup('env', 'USER') }}"
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
+controller_bootstrap_user: "{{ os_distribution }}"
 
 ###############################################################################
 # Controller network interface configuration.
diff --git a/ansible/group_vars/all/globals b/ansible/group_vars/all/globals
index e5dc329c..9d9d6e31 100644
--- a/ansible/group_vars/all/globals
+++ b/ansible/group_vars/all/globals
@@ -40,3 +40,10 @@ virtualenv_path: "{{ base_path ~ '/venvs' }}"
 # User with which to access remote hosts. This user will be created if it does
 # not exist.
 kayobe_ansible_user: "stack"
+
+###############################################################################
+# OS distribution.
+
+# OS distribution name. Valid options are "centos", "ubuntu". Default is
+# "centos".
+os_distribution: "centos"
diff --git a/ansible/group_vars/all/kolla b/ansible/group_vars/all/kolla
index 3c98b95f..33aef2c6 100644
--- a/ansible/group_vars/all/kolla
+++ b/ansible/group_vars/all/kolla
@@ -52,8 +52,9 @@ kolla_node_custom_config_path: "{{ kolla_config_path }}/config"
 ###############################################################################
 # Kolla configuration.
 
-# Kolla base container image distribution.
-kolla_base_distro: "centos"
+# Kolla base container image distribution. Options are "centos", "debian",
+# "ubuntu". Default is {{ os_distribution }}.
+kolla_base_distro: "{{ os_distribution }}"
 
 # Kolla container image type: binary or source.
 kolla_install_type: "binary"
diff --git a/ansible/group_vars/all/seed b/ansible/group_vars/all/seed
index 620dedce..decdd2a5 100644
--- a/ansible/group_vars/all/seed
+++ b/ansible/group_vars/all/seed
@@ -3,8 +3,8 @@
 # Seed node configuration.
 
 # User with which to access the seed via SSH during bootstrap, in order to
-# setup the Kayobe user account.
-seed_bootstrap_user: "{{ lookup('env', 'USER') }}"
+# setup the Kayobe user account. Default is {{ os_distribution }}.
+seed_bootstrap_user: "{{ os_distribution }}"
 
 ###############################################################################
 # Seed network interface configuration.
diff --git a/ansible/group_vars/all/seed-hypervisor b/ansible/group_vars/all/seed-hypervisor
index 2826b957..9ee93d11 100644
--- a/ansible/group_vars/all/seed-hypervisor
+++ b/ansible/group_vars/all/seed-hypervisor
@@ -3,8 +3,8 @@
 # Seed hypervisor node configuration.
 
 # User with which to access the seed hypervisor via SSH during bootstrap, in
-# order to setup the Kayobe user account.
-seed_hypervisor_bootstrap_user: "{{ lookup('env', 'USER') }}"
+# order to setup the Kayobe user account. Default is {{ os_distribution }}.
+seed_hypervisor_bootstrap_user: "{{ os_distribution }}"
 
 ###############################################################################
 # Seed hypervisor network interface configuration.
diff --git a/ansible/group_vars/all/seed-vm b/ansible/group_vars/all/seed-vm
index 5af51c36..4dcda828 100644
--- a/ansible/group_vars/all/seed-vm
+++ b/ansible/group_vars/all/seed-vm
@@ -40,8 +40,17 @@ seed_vm_root_capacity: 50G
 # Format of the seed VM root volume.
 seed_vm_root_format: qcow2
 
-# Base image for the seed VM root volume.
-seed_vm_root_image: "https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2"
+# Base image for the seed VM root volume. Default is
+# "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
+# when os_distribution is "ubuntu", or
+# "https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2"
+# otherwise.
+seed_vm_root_image: >-
+  {%- if os_distribution == 'ubuntu' %}
+  https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
+  {%- else -%}
+  https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2
+  {%- endif %}
 
 # Capacity of the seed VM data volume.
 seed_vm_data_capacity: 100G
diff --git a/ansible/group_vars/all/storage b/ansible/group_vars/all/storage
index bc218714..b474e309 100644
--- a/ansible/group_vars/all/storage
+++ b/ansible/group_vars/all/storage
@@ -3,8 +3,8 @@
 # Storage node configuration.
 
 # User with which to access the storages via SSH during bootstrap, in order
-# to setup the Kayobe user account.
-storage_bootstrap_user: "{{ lookup('env', 'USER') }}"
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
+storage_bootstrap_user: "{{ os_distribution }}"
 
 ###############################################################################
 # Storage network interface configuration.
diff --git a/etc/kayobe/bifrost.yml b/etc/kayobe/bifrost.yml
index bd7e97e1..8d20ebeb 100644
--- a/etc/kayobe/bifrost.yml
+++ b/etc/kayobe/bifrost.yml
@@ -18,14 +18,16 @@
 ###############################################################################
 # Diskimage-builder configuration.
 
-# DIB base OS element. Default is "centos".
+# DIB base OS element. Default is {{ os_distribution }}.
 #kolla_bifrost_dib_os_element:
 
-# DIB image OS release. Default is "8".
+# DIB image OS release. Default is "focal" when os_distribution is "ubuntu", or
+# "8" otherwise.
 #kolla_bifrost_dib_os_release:
 
 # List of default DIB elements. Default is ["disable-selinux",
-# "enable-serial-console", "vm"].
+# "enable-serial-console", "vm"] when os_distribution is "centos", or
+# ["enable-serial-console", "vm"] otherwise.
 #kolla_bifrost_dib_elements_default:
 
 # List of additional DIB elements. Default is none.
diff --git a/etc/kayobe/compute.yml b/etc/kayobe/compute.yml
index ab47953f..59a68fa7 100644
--- a/etc/kayobe/compute.yml
+++ b/etc/kayobe/compute.yml
@@ -3,7 +3,7 @@
 # Compute node configuration.
 
 # User with which to access the computes via SSH during bootstrap, in order
-# to setup the Kayobe user account.
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
 #compute_bootstrap_user:
 
 ###############################################################################
diff --git a/etc/kayobe/controllers.yml b/etc/kayobe/controllers.yml
index 2fbe85b6..6a4e45ee 100644
--- a/etc/kayobe/controllers.yml
+++ b/etc/kayobe/controllers.yml
@@ -3,7 +3,7 @@
 # Controller node configuration.
 
 # User with which to access the controllers via SSH during bootstrap, in order
-# to setup the Kayobe user account.
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
 #controller_bootstrap_user:
 
 ###############################################################################
diff --git a/etc/kayobe/globals.yml b/etc/kayobe/globals.yml
index bfe9b8a3..64290d92 100644
--- a/etc/kayobe/globals.yml
+++ b/etc/kayobe/globals.yml
@@ -42,6 +42,13 @@
 # not exist.
 #kayobe_ansible_user:
 
+###############################################################################
+# OS distribution.
+
+# OS distribution name. Valid options are "centos", "ubuntu". Default is
+# "centos".
+#os_distribution:
+
 ###############################################################################
 # Dummy variable to allow Ansible to accept this file.
 workaround_ansible_issue_8743: yes
diff --git a/etc/kayobe/kolla.yml b/etc/kayobe/kolla.yml
index 74f805fa..96fba266 100644
--- a/etc/kayobe/kolla.yml
+++ b/etc/kayobe/kolla.yml
@@ -61,7 +61,8 @@
 ###############################################################################
 # Kolla configuration.
 
-# Kolla base container image distribution. Default is 'centos'.
+# Kolla base container image distribution. Options are "centos", "debian",
+# "ubuntu". Default is {{ os_distribution }}.
 #kolla_base_distro:
 
 # Kolla container image type: binary or source. Default is 'binary'.
diff --git a/etc/kayobe/seed-hypervisor.yml b/etc/kayobe/seed-hypervisor.yml
index 1ef89889..b14c8234 100644
--- a/etc/kayobe/seed-hypervisor.yml
+++ b/etc/kayobe/seed-hypervisor.yml
@@ -3,7 +3,7 @@
 # Seed hypervisor node configuration.
 
 # User with which to access the seed hypervisor via SSH during bootstrap, in
-# order to setup the Kayobe user account.
+# order to setup the Kayobe user account. Default is {{ os_distribution }}.
 #seed_hypervisor_bootstrap_user:
 
 ###############################################################################
diff --git a/etc/kayobe/seed-vm.yml b/etc/kayobe/seed-vm.yml
index 0c4f8988..9ad7a743 100644
--- a/etc/kayobe/seed-vm.yml
+++ b/etc/kayobe/seed-vm.yml
@@ -24,7 +24,10 @@
 #seed_vm_root_format:
 
 # Base image for the seed VM root volume. Default is
+# "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
+# when os_distribution is "ubuntu", or
 # "https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2"
+# otherwise.
 #seed_vm_root_image:
 
 # Capacity of the seed VM data volume.
diff --git a/etc/kayobe/seed.yml b/etc/kayobe/seed.yml
index 88efbcc7..35f2aada 100644
--- a/etc/kayobe/seed.yml
+++ b/etc/kayobe/seed.yml
@@ -3,7 +3,7 @@
 # Seed node configuration.
 
 # User with which to access the seed via SSH during bootstrap, in order to
-# setup the Kayobe user account.
+# setup the Kayobe user account. Default is {{ os_distribution }}.
 #seed_bootstrap_user:
 
 ###############################################################################
diff --git a/etc/kayobe/storage.yml b/etc/kayobe/storage.yml
index c8ee66f6..47f63dba 100644
--- a/etc/kayobe/storage.yml
+++ b/etc/kayobe/storage.yml
@@ -3,7 +3,7 @@
 # Storage node configuration.
 
 # User with which to access the storages via SSH during bootstrap, in order
-# to setup the Kayobe user account.
+# to setup the Kayobe user account. Default is {{ os_distribution }}.
 #storage_bootstrap_user:
 
 ###############################################################################
diff --git a/releasenotes/notes/os-distribution-69445eb19a611d43.yaml b/releasenotes/notes/os-distribution-69445eb19a611d43.yaml
new file mode 100644
index 00000000..69c1f881
--- /dev/null
+++ b/releasenotes/notes/os-distribution-69445eb19a611d43.yaml
@@ -0,0 +1,14 @@
+---
+features:
+  - |
+    Adds an ``os_distribution`` variable in ``etc/kayobe/globals.yml``, with a
+    default value of ``centos``. The variable can also be set to ``ubuntu``,
+    and sets sensible default values for other variables.
+upgrade:
+  - |
+    Modifies the default value of ``controller_bootstrap_user``,
+    ``compute_bootstrap_user``, ``seed_bootstrap_user``,
+    ``seed_hypervisor_bootstrap_user`` and ``storage_bootstrap_user`` from
+    using the ``$USER`` environment variable of the Ansible control host to
+    ``os_distribution``. This provides a more predictable default that does not
+    depend on the Ansible execution environment.
-- 
GitLab