Using opscode chef, is there a way to find or loop over all user accounts?
I need to create a configuration file in each users home directory. I do not want to loop over any directory structure for this.
Using opscode chef, is there a way to find or loop over all user accounts?
I need to create a configuration file in each users home directory. I do not want to loop over any directory structure for this.
All users on the system are automatically detected by ohai when Chef runs, and available in the
node['etc']
attribute space. Users arenode['etc']['passwd']
. You can iterate over this like a hash. You can exclude "system" or "precreated by packages" by comparing whether a user's numeric ID is over whatever is defined in your systems /etc/login.defs UID_MIN.Example usage in a recipe to create a config file that you have stored in the cookbook, a different file for each user.
Replace "custom_config" with whatever your config file is named.
It looks like ohai's etc.passwd support is based on Ruby Etc.passwd which reads the
/etc/passwd
file.This could be fine if your users are defined statically like this. If your server has users defined in a remote system like LDAP or NIS then those users will not be in /etc/passwd. You can list them with