From nobody Fri Jun 5 06:40:30 2026 X-Original-To: dev-commits-src-main@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 4gWsJG6hW4z6gXSl for ; Fri, 05 Jun 2026 06:40:30 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gWsJG3lxvz3Rcm for ; Fri, 05 Jun 2026 06:40:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780641630; 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=hJ/7/0pQ81+Mq28xT2GhJUsZfXgOqwD+JImPK8nmkq4=; b=KIV1k55kizTAsRJSxoPogGiP6M/dyw07kPrmiQUXb/7mTMk2ey8P68mhZxFrcf2JW7VbjP OqccSV1JukqwPvYsOPkWf6sYYSV/9ZOakfBiNf99qDWeWLDY7sYpwxdCMcRwzwQzAvfj6Q vz0J1ARpyrpU5mnCQ6YIJ/SNK5xo5Tf4NNIu4rM1xd3PJEUQAi5vC1xkbOV+8GinZ7E1Np +17KA45h87ouJF7o6gtliO17Ma3+lCGRCwrpT08ONTx2l4lVopVCxKQoXvrffK93VSnede sLM6o4pxw5KY9oiwjWrqDvtdFgkenPRsks4SIymSwT35x2Q895NwDsf9icFNAA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780641630; a=rsa-sha256; cv=none; b=E8v9UC30QINCAZ5mVlypZaw78MpaULRVAqf8u82WEitQ69M+jMYKXdId3PuAyCiJ8DSJoH Nb6VvatBIkH5y3pJrGdbVjg1d+GCEyOmqTKRBQzckTBx0iKM8E02i+cHvcP1E3AzbNSlim KNbM4V2/eIsUqGQTdoprM/KsG+h58YYTADOSaY1quK7Zu8ORrDUjPYOznAjSVBNkUqR84y pt3YAbOxJNCamjmGPrA9DAKCYvtwyMU/T5YjleSXllr+lOQkQqxzAQrGKd/pcx5clDCa46 L28KfldfJMPryAOGIOAQ5Bvgd8jTocj+GNC+bPnhONXhxiW4vTvdSvF4xYpbHg== 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=1780641630; 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=hJ/7/0pQ81+Mq28xT2GhJUsZfXgOqwD+JImPK8nmkq4=; b=gG6oEos5+jpKkKrJmLYDVIVYLhGU87WX0X8cCUvqEuw3HBUdIwq0y+05HMNhHMVvU6JUW7 HXRMF2aXJkpvB/omCEdgKXaiXeTMD5jzmraNVEeGzmejFe5Mz3jKK+iBMCqcNjYE6YF14V X9PKaR4QezyDLphwKnJcCVGUPyQq9uVStfxht+hRJvV5QYwg1bOy2yb1qq1t/eQ6TggR6a RcK7DWceRkdlhIU1GXEmK5/Wzubtd7NQko71t8yrte9ZyFDIwApM+5KYz+btWhlUBrVB+k icgZhejH76ofEf30ltNCBjpjqcumVsjAtSOvY8j/Bvt+DPirX5+8FiMyZaSbLw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gWsJG3HL1z37j for ; Fri, 05 Jun 2026 06:40:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3212f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 05 Jun 2026 06:40:30 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: ba58e8ad7263 - main - nuageinit: implement manage_etc_hosts support List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ba58e8ad726318ed59b6cc5934435dbddbe23dac Auto-Submitted: auto-generated Date: Fri, 05 Jun 2026 06:40:30 +0000 Message-Id: <6a226f5e.3212f.5121859f@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ba58e8ad726318ed59b6cc5934435dbddbe23dac commit ba58e8ad726318ed59b6cc5934435dbddbe23dac Author: Baptiste Daroussin AuthorDate: 2026-06-05 05:49:16 +0000 Commit: Baptiste Daroussin CommitDate: 2026-06-05 05:49:16 +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. --- 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