Home Directory Is Not Created with Adding User Resource with Chef

home directory is not created with adding user resource with chef

While system users usually don't have a home dir, chef will create the home dir even for system users if you specify home. I've tried it, and cannot reproduce the issue.

What is going on is a little bit hidden in the documentation. The chef documentations says:

system | Use to create a system user. This attribute may be used with useradd as the provider to create a system user which passes the -r flag to useradd.

If have a look at the man page of useradd:

-r, --system
Create a system account.

System users will be created with no aging information in /etc/shadow,
and their numeric identifiers are chosen in the SYS_UID_MIN-SYS_UID_MAX
range, defined in >/etc/login.defs, instead of UID_MIN-UID_MAX
(and their GID counterparts for the creation of groups).

Note that useradd will not create a home directory for such an user,
regardless of the default setting in /etc/login.defs (CREATE_HOME).
You have to specify the -m options if you want a home directory for
a system account to be created.

However, it seems like chef is passing the -m option explicitly if you specify a home dir. I could not reproduce this issue therefore.

Chef doesn't create home directory for user

You passed deploy to the user resource name instead of node['deploy_user']:

user node['deploy_user'] do
action :create
comment 'Application deploy user'
home "/home/#{node['deploy_user']}"
shell '/bin/bash'
system true
supports manage_home: true
end

Created user resource with Chef, can't authenticate and home not created

Try the following

openssl passwd -1 "mypassword"

Password $1$YwUKq1QX$qIVeFlybWqOKJjRLed29j

user "myuser" do  
supports :manage_home => true
shell "/bin/bash"
home "/home/myuser"
comment "Created by Chef"
password $1$YwUKq1QX$qIVeFlybWqOKJjRLed29j.
system true
provider Chef::Provider::User::Useradd
action :create
end

chef user resource does not update an existing user's home directory if it already exists

Unfortunately the only thing :manage_home => true does is creating the home directory if it does not exist. If it exists it does nothing, even if there are wrong permissions.

I have a directory resource coming after every user resource, that makes sure home folder is correct:

directory '/home/postgres' do
owner 'postgres'
group 'postgres'
mode 0755
end

Chef Windows: Create the home directory when creating Windows User

Soundslike XY problem there.

I suspect you wish to create the use directory to set in some settings or documents for your users.

In windows the actual way to accomplish this is to work with default user and all users home dirs.

The content of All Users will be merged with each users directory on the workstation (i.e: a shortcut placed in All Users\Desktop will be on each user desktop and they can't delete it, usefull for support link or other parts shared by all users)

The content of Default User is the User home Template, at the first connection of a user , this user home directory will be created by copying the content of what is in Default User directory (including shortcuts on desktop, documents in the my document dir, etc.)

So the answer for your case is more to work on the Default User or All Users path than trying to create and work on each User Home dir. If there's scripts you wish to set there specific to each user, use %USERNAME% and %USERPROFILE% in thoose scripts to get the username and it's profiles diretory.

directory resource does not create directory

Chef has two phases of execution: a compile phase and a converge phase.

In the compile phase, any resource declarations you write (like directory) are compiled but not executed. Any bare Ruby code you write is also executed at this time. In the converge phase, any compiled resources are then converged in a test-and-set operation.

I'm going to assume that at work, you already have a /downloads directory pre-existing, so the resource is a no-op during converge, and the raise doesn't happen during compile.

If you want arbitrary Ruby code to execute at converge time, put it in a ruby_block resource.

Can't create a directory in node

~ or $HOME have no meaning in ruby, they're ok in shell context.

directory "#{ENV['HOME']}/build" would be better.

it will create the directory in the home dir of the user running chef.

Chef recipe - how to run a resource only if user resource did manage_home

Resources have the ability to notify other resources, on any state change.

user "whatever" do
action :modify
notifies :run, "bash[modify user]", :immediately
end

You can change the default action of your resource to :nothing, then the resource will only run on the notify.

bash "modify user" do
command "ls"
action :nothing
end

What constitutes a "state change" is controlled inside resources, but it should normally be triggered if any actions at all were taken by the resource (This is set with a flag in the resource called updated_by_last_action). This may not exactly meet your manage_home requirement but it's better than your bash running all the time.



Related Topics



Leave a reply



Submit