Skarab
Skarab

Reputation: 7141

How to get all the members of a group in chef?

Is there a more-elegant method for getting users (in a given group) in chef than iterating over etc/passwd? I suppose I could use search functionality to get the list of group members from data bags.

Upvotes: 0

Views: 904

Answers (2)

94230
94230

Reputation: 156

You can also get the group members using getent

def get_local_users_within_gid(gid)
  # return list of users
  shell_out!("getent group #{gid}").stdout.strip().split(':').last.split(',')
end

Upvotes: 0

StephenKing
StephenKing

Reputation: 37630

Yes, ohai gives you such information. You can access these automatic attributes like any other attribute.

You find information about the groups in node[:etc][:group]

Upvotes: 1

Related Questions