Error executing action `create` on resource 'linux_user[jdoe]'

Please can someone HELP OUT with the erro below while trying to add system users with users cookbook.
Error Log & Stacktrace

users_manage[developers] (users::developers line 4) had an error: Mixlib::ShellOut::ShellCommandFailed: linux_user[jdoe] (/home/ubuntu/C:efche/cookbooks/users/resources/manage.rb line 99) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '6'
---- Begin output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
STDOUT:
STDERR: useradd: group '2004' does not exist
---- End output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
Ran ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] returned 6

Mixlib::ShellOut::ShellCommandFailed

linux_user[jdoe] (/home/ubuntu/C:efche/cookbooks/users/resources/manage.rb line 99) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '6'
---- Begin output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
STDOUT:
STDERR: useradd: group '2004' does not exist
---- End output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
Ran ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] returned 6

Cookbook Trace: (most recent call first)

/home/ubuntu/C:efche/cookbooks/users/resources/manage.rb:99:in block (2 levels) in class_from_file' /home/ubuntu/C:efche/cookbooks/users/resources/manage.rb:53:in each'
/home/ubuntu/C:efche/cookbooks/users/resources/manage.rb:53:in `block in class_from_file'

Resource Declaration:

Compiled Resource:

Declared in /home/ubuntu/C:efche/cookbooks/users/recipes/developers.rb:4:in `from_file'

users_manage("developers") do
action [:remove, :create]
updated true
updated_by_last_action true
default_guard_interpreter :default
declared_type :users_manage
cookbook_name "users"
recipe_name "developers"
group_id 2301
users [data_bag_item["users", "jdoe", {"id"=>"jdoe", "uid"=>"2004", "gid"=>"2004", "home"=>"/home/jdoe", "groups"=>["sysadmins", "developers"], "comment"=>"John Doe", "ssh_keys"=>}]]
group_name "developers"
cookbook "users"
end

Hello sforze1,
The group has to exist before you can attach it to a user.

STDERR: useradd: group '2004' does not exist

-George

Thanks for your responds George,

The group already exist and was created with the data bag user setup but I still get the same error
Error executing action create on resource 'users_manage[developers]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
linux_user[jdoe] (/root/Cefche/cookbooks/users/resources/manage.rb line 99) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '6'
---- Begin output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
STDOUT: 
STDERR: useradd: group '2004' does not exist
---- End output of ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] ----
Ran ["useradd", "-c", "John Doe", "-g", "2004", "-s", "/bin/sh", "-u", "2004", "-d", "/home/jdoe", "-m", "jdoe"] returned 6

Cookbook Trace: (most recent call first)
----------------------------------------
/root/Cefche/cookbooks/users/resources/manage.rb:99:in `block (2 levels) in class_from_file'
/root/Cefche/cookbooks/users/resources/manage.rb:53:in `each'
/root/Cefche/cookbooks/users/resources/manage.rb:53:in `block in class_from_file'

Resource Declaration:
---------------------


Compiled Resource:
------------------
# Declared in /root/Cefche/cookbooks/users/recipes/developers.rb:4:in `from_file'

users_manage("developers") do
  action [:remove, :create]
  default_guard_interpreter :default
  declared_type :users_manage
  cookbook_name "users"
  recipe_name "developers"
  group_id 2301
  users [data_bag_item["users", "jdoe", {"id"=>"jdoe", "uid"=>"2004", "gid"=>"2004", "home"=>"/home/jdoe", "groups"=>["sysadmins", "developers"], "comment"=>"John Doe", "ssh_keys"=>[]}]]
  group_name "developers"
  cookbook "users"
end

System Info:
------------
chef_version=17.4.38
platform=ubuntu
platform_version=18.04
ruby=ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
program_name=/usr/bin/chef-client
executable=/opt/chef/bin/chef-client

Have you tried running a command like this in your recipe or on the node to see if the group is found?

getent group | grep 2004

Is this group in ldap or a local group? If in ldap is the node setup for ldap when you run this recipe?

-George

root@ip-10-0-0-228:~# getent group | grep 2004
2004:x:2303:
This is a local group not ldap

There's the problem. Your group id is 2303 and group name is 2004. useradd -g is for group id so you need to use 2303 unless you have used the wrong group name when you created the group.

-George

Thanks George,
Yes that was the issue. But do I need to manually add group id when ever i need to create a new user?

Thanks, I think I figured it out. The gid and name was a little confusing to me.
Thanks a lot.