feat(ansible): accept hostname alias
Some checks are pending
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run
CI / auto-merge (push) Waiting to run

This commit is contained in:
Virgil 2026-04-03 13:04:55 +00:00
parent 17691b9ff0
commit bbe110c1c0
2 changed files with 20 additions and 0 deletions

View file

@ -2522,6 +2522,9 @@ func containsInt(values []int, target int) bool {
func (e *Executor) moduleHostname(ctx context.Context, client sshExecutorClient, args map[string]any) (*TaskResult, error) {
name := getStringArg(args, "name", "")
if name == "" {
name = getStringArg(args, "hostname", "")
}
if name == "" {
return nil, coreerr.E("Executor.moduleHostname", "name required", nil)
}

View file

@ -191,6 +191,23 @@ func TestModulesAdv_ModuleHostname_Good_ChangesWhenDifferent(t *testing.T) {
assert.True(t, mock.hasExecuted(`sed -i`))
}
func TestModulesAdv_ModuleHostname_Good_HostnameAlias(t *testing.T) {
e, mock := newTestExecutorWithMock("host1")
mock.expectCommand(`^hostname$`, "old-host\n", "", 0)
mock.expectCommand(`hostnamectl set-hostname "alias-host" \|\| hostname "alias-host"`, "", "", 0)
mock.expectCommand(`sed -i 's/127\.0\.1\.1\..*/127.0.1.1\talias-host/' /etc/hosts`, "", "", 0)
result, err := e.moduleHostname(context.Background(), mock, map[string]any{
"hostname": "alias-host",
})
require.NoError(t, err)
assert.True(t, result.Changed)
assert.False(t, result.Failed)
assert.True(t, mock.hasExecuted(`hostnamectl set-hostname`))
assert.True(t, mock.hasExecuted(`sed -i`))
}
// --- group module ---
func TestModulesAdv_ModuleGroup_Good_CreateNewGroup(t *testing.T) {