diff --git a/elements/base/README.rst b/elements/base/README.rst index 6f8c27ddc..c2a4412cb 100644 --- a/elements/base/README.rst +++ b/elements/base/README.rst @@ -6,6 +6,20 @@ This is the base element. Almost all users will want to include this in their disk image build, as it includes a lot of useful functionality. +The `DIB_CLOUD_INIT_ETC_HOSTS` environment variable can be used to +customize cloud-init's management of `/etc/hosts`: + + * If the variable is set to something, write that value as + cloud-init's manage_etc_hosts. + + * If the variable is set to an empty string, don't create + manage_etc_hosts setting (cloud-init will use its default value). + + * If the variable is not set, use "localhost" for now. Later, not + setting the variable will mean using cloud-init's default. (To + preserve diskimage-builder's current default behavior in the + future, set the variable to "localhost" explicitly.) + Notes: * If you are getting warnings during the build about your locale diff --git a/elements/base/install.d/10-cloud-init b/elements/base/install.d/10-cloud-init index d696c1c79..3eea9af9d 100755 --- a/elements/base/install.d/10-cloud-init +++ b/elements/base/install.d/10-cloud-init @@ -9,6 +9,15 @@ set -o pipefail # cloud-init May not actually be installed mkdir -p /etc/cloud/cloud.cfg.d -dd of=/etc/cloud/cloud.cfg.d/10_etc_hosts.cfg << EOF -manage_etc_hosts: localhost + +if [ ! -v DIB_CLOUD_INIT_ETC_HOSTS ]; then + echo "WARNING: In the future the default setting for manage_etc_hosts will not be overridden by this element." + echo "WARNING: Set DIB_CLOUD_INIT_ETC_HOSTS to 'localhost' to preserve current behavior." +fi + +DIB_CLOUD_INIT_ETC_HOSTS=${DIB_CLOUD_INIT_ETC_HOSTS-localhost} +if [ -n "$DIB_CLOUD_INIT_ETC_HOSTS" ]; then + dd of=/etc/cloud/cloud.cfg.d/10_etc_hosts.cfg << EOF +manage_etc_hosts: $DIB_CLOUD_INIT_ETC_HOSTS EOF +fi