From: Luis Chamberlain <mcgrof@kernel.org>
To: Chuck Lever <cel@kernel.org>, Daniel Gomez <da.gomez@kruces.com>,
kdevops@lists.linux.dev
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 1/3] common: use fallback for group inference on remote systems
Date: Wed, 27 Aug 2025 02:32:12 -0700 [thread overview]
Message-ID: <20250827093215.3540056-2-mcgrof@kernel.org> (raw)
In-Reply-To: <20250827093215.3540056-1-mcgrof@kernel.org>
When provisioning remote bare metal systems or VMs with different
user configurations, getent group <username> may fail if the user's
primary group has a different name. This is common in:
- Enterprise environments with LDAP/AD integration
- Bare metal systems with pre-existing user configurations
- Systems like NixOS with different group naming conventions
- Cloud/managed hosting with auto-generated group names
Add fallback to extract the primary GID from the passwd entry and
look up the group by GID, which is more reliable across diverse
system configurations.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
playbooks/roles/common/tasks/main.yml | 29 +++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/playbooks/roles/common/tasks/main.yml b/playbooks/roles/common/tasks/main.yml
index 3ee08018..bb92fea8 100644
--- a/playbooks/roles/common/tasks/main.yml
+++ b/playbooks/roles/common/tasks/main.yml
@@ -55,9 +55,34 @@
when:
- infer_uid_and_group|bool
-- name: Override user and group with inferred settings if feature is enabled
- ansible.builtin.set_fact:
+- name: Get primary group ID from user entry
+ set_fact:
+ user_primary_gid: "{{ getent_running_user.ansible_facts.getent_passwd[target_user][2] }}"
+ when:
+ - infer_uid_and_group|bool
+ - getent_on_group.rc | default(1) != 0
+
+- name: Run getent against the primary group ID
+ getent:
+ database: group
+ key: "{{ user_primary_gid }}"
+ register: getent_primary_group
+ when:
+ - infer_uid_and_group|bool
+ - getent_on_group.rc | default(1) != 0
+
+- name: Override user and group with inferred settings if feature is enabled (group found by name)
+ set_fact:
data_user: "{{ target_user }}"
data_group: "{{ ((getent_on_group.values() | first).values() | first).keys() | first }}"
when:
- infer_uid_and_group|bool
+ - getent_on_group.rc | default(1) == 0
+
+- name: Override user and group with inferred settings if feature is enabled (group found by GID)
+ set_fact:
+ data_user: "{{ target_user }}"
+ data_group: "{{ getent_primary_group.ansible_facts.getent_group.keys() | first }}"
+ when:
+ - infer_uid_and_group|bool
+ - getent_on_group.rc | default(1) != 0
--
2.50.1
next prev parent reply other threads:[~2025-08-27 9:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 9:32 [PATCH 0/3] kdevops: add initial nixos support Luis Chamberlain
2025-08-27 9:32 ` Luis Chamberlain [this message]
2025-08-27 9:32 ` [PATCH 2/3] nixos: add NixOS support as third bringup option with libvirt integration Luis Chamberlain
2025-08-27 9:32 ` [PATCH 3/3] mirror: add Nix binary cache mirroring support Luis Chamberlain
2025-08-29 7:50 ` [PATCH 0/3] kdevops: add initial nixos support Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250827093215.3540056-2-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=cel@kernel.org \
--cc=da.gomez@kruces.com \
--cc=kdevops@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox