From 8fefd3af074ba4db5e8cb01f5d14363a368662dd Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Thu, 27 Jan 2022 17:47:58 +0000 Subject: [PATCH 1/3] Adds etc-hosts element --- elements/etc-hosts/README.rst | 6 ++++++ elements/etc-hosts/environment.d/etc-hosts | 3 +++ elements/etc-hosts/pre-install.d/01-etc-hosts | 9 +++++++++ 3 files changed, 18 insertions(+) create mode 100644 elements/etc-hosts/README.rst create mode 100755 elements/etc-hosts/environment.d/etc-hosts create mode 100755 elements/etc-hosts/pre-install.d/01-etc-hosts diff --git a/elements/etc-hosts/README.rst b/elements/etc-hosts/README.rst new file mode 100644 index 0000000..17e7278 --- /dev/null +++ b/elements/etc-hosts/README.rst @@ -0,0 +1,6 @@ +========= +etc-hosts +========= +Appends text to /etc/hosts. + +`DIB_ETC_HOSTS_EXTRA`: Lines to add to /etc/hosts diff --git a/elements/etc-hosts/environment.d/etc-hosts b/elements/etc-hosts/environment.d/etc-hosts new file mode 100755 index 0000000..e1d647c --- /dev/null +++ b/elements/etc-hosts/environment.d/etc-hosts @@ -0,0 +1,3 @@ +#!/bin/bash + +export ETC_HOSTS_EXTRA=${DIB_ETC_HOSTS_EXTRA:?"You must define DIB_ETC_HOSTS_EXTRA"} diff --git a/elements/etc-hosts/pre-install.d/01-etc-hosts b/elements/etc-hosts/pre-install.d/01-etc-hosts new file mode 100755 index 0000000..b9c897c --- /dev/null +++ b/elements/etc-hosts/pre-install.d/01-etc-hosts @@ -0,0 +1,9 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +echo "$ETC_HOSTS_EXTRA" >> /etc/hosts From 28fcafbe49555d38af574814b337a7c89a79fb83 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Thu, 27 Jan 2022 17:56:07 +0000 Subject: [PATCH 2/3] echo doesn't handle newlines --- elements/etc-hosts/pre-install.d/01-etc-hosts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/etc-hosts/pre-install.d/01-etc-hosts b/elements/etc-hosts/pre-install.d/01-etc-hosts index b9c897c..b5ec9b3 100755 --- a/elements/etc-hosts/pre-install.d/01-etc-hosts +++ b/elements/etc-hosts/pre-install.d/01-etc-hosts @@ -6,4 +6,4 @@ fi set -eu set -o pipefail -echo "$ETC_HOSTS_EXTRA" >> /etc/hosts +printf "$ETC_HOSTS_EXTRA" >> /etc/hosts From 1522b7d76b9329c1745893cdb48a8f0af39d06d5 Mon Sep 17 00:00:00 2001 From: Alex-Welsh Date: Thu, 16 Feb 2023 11:08:37 +0000 Subject: [PATCH 3/3] Added etc-hosts example to readme --- elements/etc-hosts/README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/elements/etc-hosts/README.rst b/elements/etc-hosts/README.rst index 17e7278..6f7a1ae 100644 --- a/elements/etc-hosts/README.rst +++ b/elements/etc-hosts/README.rst @@ -4,3 +4,13 @@ etc-hosts Appends text to /etc/hosts. `DIB_ETC_HOSTS_EXTRA`: Lines to add to /etc/hosts + +For example: + + .. code-block:: + + export DIB_ETC_HOSTS_EXTRA="192.168.20.1 compute-host-01" + +Or: + + export DIB_ETC_HOSTS_EXTRA=`cat ./my-hosts` \ No newline at end of file