From nobody Sun Jun 28 18:40:31 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gpJBS1875z6jkQy for ; Sun, 28 Jun 2026 18:40:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gpJBR59mDz3Y0l for ; Sun, 28 Jun 2026 18:40:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782672031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kKVO8b8+P5vBGiH2OIUb5+0TubbEFNWtZS0NIlAqGoY=; b=ysJUGeSa8nu+Vfr7KLwO/+LS/J+EU1S6DnqzbQyf0zfxxm/EI1Cq3uY/BHNHj+YJreoXv5 rQ9tirTV8ugulw61Ee53lYRwjv+KFe2/klOiEmegbgc84vo8LHyE3HgbYk+ewxwpnMrX0j azCdmIl/XsQzA4pFxsEqwFBuLIDQqK4td2onkHeB5sBM61NQY1KHAap7WeiStR/PUBI67M jCRnqyHIxtYzVlwSoSF8WwKjnQA5uAVVUon+BG0shtMMXlZ3xJK2viWYMvv6TVhUTSt22M 1c9nj68ch8XTSNg7Q45WsLJDFz1xkPfZMJ9QU1++2s3VAd7jkBQVUM6a2d5bdw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782672031; a=rsa-sha256; cv=none; b=unom005J55qtqgbxo5oniRr8YEHW5LBGZcAQPu7rsHn3g/DXOD5e3F7Yckakxy/wfL1mc0 0eWzElbflNTZV4Wz/VCXqlnCgVy52wp/06eAXO8TOxhUulmGeTZiUb/zWPkJ8kvivQVz1s VUNzy9yRJevCtWFGvgpaDmbeUODhTap3Ps7BXw/yNgBEDenagnqugTu82hTPBhzsQoJX2k 0RtEZNHZ3N8uX/ySOWsnLmJzdxlQg104ldIlkKRcvx+ZUYLc2RyJQq6OvUmyQvkSgKPmcK 7/glifGU14xOfVqe9vGlpRxCAyCrfofwtdd6NP2CAtt8p1SvHaGwn3AMwfx9eQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782672031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kKVO8b8+P5vBGiH2OIUb5+0TubbEFNWtZS0NIlAqGoY=; b=jw6+JM69Md3aBxtI+RRUeqnNuasXvYrA+OCAAnwsjKkKxG98nAAz1iK5nKX60M7HxZO6Xs FlP7dyGjxAxt7+OlZfoElC6774t+Rtj6Zr9Tvi7lk4XeG2+q+oxOCKbUqICbdGEuGDHTRK mR93BwFVJlcv7vU3Q5RTamRV7azxPNsnxNWqnTcuWz9PLKoMh1g6srWQ3vCelh/MeugMZw 7a4uixjXhqKPdqWZWv6LK33lYgfZkEG4DzU/1M48EKUBb0MRppvZ2EnF1jAKkjx+JeUIG9 1WyDgZIiLVqnecmObf7HQb5uYQwbamY2HzyzQQeEYG3AiRP4TQAmhezwyHY++A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gpJBR4FWPz739 for ; Sun, 28 Jun 2026 18:40:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1cb4f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 28 Jun 2026 18:40:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 85a943339f2d - stable/15 - nuageinit: implement manage_etc_hosts support List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 85a943339f2df12c2ccc501c54c95afcf4c59e76 Auto-Submitted: auto-generated Date: Sun, 28 Jun 2026 18:40:31 +0000 Message-Id: <6a416a9f.1cb4f.6066be74@gitrepo.freebsd.org> The branch stable/15 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=85a943339f2df12c2ccc501c54c95afcf4c59e76 commit 85a943339f2df12c2ccc501c54c95afcf4c59e76 Author: Baptiste Daroussin AuthorDate: 2026-06-05 05:49:16 +0000 Commit: Baptiste Daroussin CommitDate: 2026-06-28 18:32:26 +0000 nuageinit: implement manage_etc_hosts support Add support for adding the instance hostname to /etc/hosts on the 127.0.0.1 and ::1 localhost lines, matching cloud-init's default behaviour (manage_etc_hosts: true). create a revolve_hostname helper to avoid code duplucation. (cherry picked from commit ba58e8ad726318ed59b6cc5934435dbddbe23dac) --- libexec/nuageinit/nuage.lua | 62 +++++++++++++++++++++++++++++++++++++++++++ libexec/nuageinit/nuageinit | 30 ++++++++++++++++----- libexec/nuageinit/nuageinit.7 | 13 +++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index 7cce4c9bece1..45e14ef0ce21 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -162,6 +162,67 @@ local function sethostname(hostname) f:close() end +local function update_etc_hosts(root, hostname) + if hostname == nil or hostname == "" then + return + end + local hosts_path = root .. "/etc/hosts" + local lines = {} + local already_present = false + + local f = io.open(hosts_path, "r") + if not f then + -- File doesn't exist, create a minimal one + local nf = io.open(hosts_path, "w") + if not nf then + warnmsg("unable to create " .. hosts_path) + return + end + nf:write("::1\t\tlocalhost " .. hostname .. "\n") + nf:write("127.0.0.1\t\tlocalhost " .. hostname .. "\n") + nf:close() + return + end + + for line in f:lines() do + if line:find(hostname, 1, true) then + already_present = true + end + table.insert(lines, line) + end + f:close() + + if already_present then + return + end + + -- Not present, append to localhost lines + local new_lines = {} + local found_localhost = false + for _, line in ipairs(lines) do + if (line:match("^127%.0%.0%.1%s") or line:match("^::1%s")) and line:find("localhost", 1, true) then + table.insert(new_lines, line .. " " .. hostname) + found_localhost = true + else + table.insert(new_lines, line) + end + end + + if not found_localhost then + table.insert(new_lines, "127.0.0.1\t\tlocalhost " .. hostname) + end + + f = io.open(hosts_path, "w") + if not f then + warnmsg("unable to open " .. hosts_path .. " for writing") + return + end + for _, line in ipairs(new_lines) do + f:write(line .. "\n") + end + f:close() +end + local function splitlist(list) local ret = {} if type(list) == "string" then @@ -775,6 +836,7 @@ local n = { addsshkey = addsshkey, update_sshd_config = update_sshd_config, delete_ssh_host_keys = delete_ssh_host_keys, + update_etc_hosts = update_etc_hosts, chpasswd = chpasswd, pkg_bootstrap = pkg_bootstrap, install_package = install_package, diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index bfe5f893756e..9d2f3c6024c4 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -99,16 +99,23 @@ local function get_ifaces_by_mac() return myifaces end -local function sethostname(obj, metadata) - -- always prefer fqdn if specified over hostname +local function resolve_hostname(obj, metadata) if obj and obj.fqdn then - nuage.sethostname(obj.fqdn) + return obj.fqdn elseif obj and obj.hostname then - nuage.sethostname(obj.hostname) + return obj.hostname elseif metadata["local-hostname"] then - nuage.sethostname(metadata["local-hostname"]) + return metadata["local-hostname"] elseif metadata["hostname"] then - nuage.sethostname(metadata["hostname"]) + return metadata["hostname"] + end + return nil +end + +local function sethostname(obj, metadata) + local hostname = resolve_hostname(obj, metadata) + if hostname then + nuage.sethostname(hostname) end end @@ -541,6 +548,16 @@ local function bootcmd(obj) end end +local function manage_etc_hosts(obj, metadata) + if obj.manage_etc_hosts == false then + return + end + local hostname = resolve_hostname(obj, metadata) + if hostname then + nuage.update_etc_hosts(root, hostname) + end +end + local function runcmd(obj) if obj.runcmd == nil then return end local f = nil @@ -813,6 +830,7 @@ elseif line == "#cloud-config" then local pre_network_calls = { bootcmd, sethostname, + manage_etc_hosts, settimezone, groups, create_default_user, diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7 index 3cc0eceeb2ae..66a72324f414 100644 --- a/libexec/nuageinit/nuageinit.7 +++ b/libexec/nuageinit/nuageinit.7 @@ -146,6 +146,19 @@ Specify a fully qualified domain name for the instance. Specify the hostname of the instance if .Qq Ic fqdn is not set. +.It Ic manage_etc_hosts +Boolean which determines whether the hostname should be added to +.Pa /etc/hosts +on the +.Qq 127.0.0.1 +and +.Qq ::1 +localhost lines. +Defaults to +.Ar true . +Set to +.Ar false +to skip this behaviour. .It Ic timezone Sets the system timezone based on the value provided. .Pp