# It's empty!
# include_recipe 'users::default'
include_recipe 'sudo::default'

groups = node['basic']['groups']
sudo_usernames = node['basic']['sudo'] ? node['basic']['sudo']['usernames'] : nil
sudo_groups = node['basic']['sudo'] ? node['basic']['sudo']['groups'] : nil
sudo_usernames_nopasswd = node['basic']['sudo'] ? node['basic']['sudo']['usernames_nopasswd'] : nil

if groups
  groups.each do |groupname, group|
    users_manage groupname do
      group_id group['gid']
      group_name groupname
      action :create
    end
  end
end

if sudo_usernames
  sudo_usernames.each do |sudo_username|
    sudo sudo_username do
      user "%#{sudo_username}"
      runas 'root'
      commands ['ALL']
      host 'ALL'
      nopasswd false
    end
  end
end

if sudo_groups
  sudo_groups.each do |sudo_group|
    sudo sudo_group do
      group "%#{sudo_group}"
      runas 'root'
      commands ['ALL']
      host 'ALL'
      nopasswd false
    end
  end
end

if sudo_usernames_nopasswd
  sudo_usernames_nopasswd.each do |sudo_username_nopasswd|
    sudo sudo_username_nopasswd do
      user "%#{sudo_username_nopasswd}"
      runas 'root'
      commands ['ALL']
      host 'ALL'
      nopasswd true
    end
  end
end
