Chef 不为用户创建主目录
Chef doesn't create home directory for user
我有一个厨师食谱来创建部署用户。 运行 kitchen converge
时正在创建用户。尝试为用户创建 .ssh
文件夹时失败,因为用户的主目录不存在。 Parent directory /home/deploy does not exist, cannot create /home/deploy/.ssh
。
cookbooks/main/recipes/user.rb
user deploy do
action :create
comment 'Application deploy user'
home "/home/#{node['deploy_user']}"
shell '/bin/bash'
system true
supports manage_home: true
end
directory "/home/#{node['deploy_user']}/.ssh" do
mode 0700
owner node['deploy_user']
group node['deploy_user']
end
template "/home/#{node['deploy_user']}/.ssh/authorized_keys" do
mode 0600
owner node['deploy_user']
source 'authorized_keys.erb'
end
.kitchen.yml
---
driver:
name: vagrant
provisioner:
name: chef_solo
platforms:
- name: ubuntu-14.04
- name: centos-7.1
suites:
- name: default
run_list:
- recipe[main::default]
attributes:
您将 deploy
传递给用户资源名称而不是 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
来自man useradd
:
-r, --system
Create a system account.
System users will be created with no aging information in /etc/shadow, and their numeric identifiers are choosen 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.
或者简而言之,将 manage_home true
添加到您的资源中。
可能是运行顺序问题。尝试
user node['deploy_user'] do
comment 'Application deploy user'
home "/home/#{node['deploy_user']}"
shell '/bin/bash'
system true
manage_home true
end.run_action(:create)
这也激怒了我。大厨没有理由不让这么简单的日常动作变得容易执行。
由于这是 google 的热门搜索,我不清楚其他答案是否正确,这正是我 运行 需要的答案。我正在使用厨师服务器 12.4 和客户端 12.10.24。全部在 Ubuntu 14.04.
user '<USERNAME>' do
gid '<MY_GROUP_NAME>'
shell '/bin/bash'
comment 'some stuff i want to say'
home "/home/<USERNAME>"
supports manage_home: true
action :create
end
我的/etc/login.defs 文件是未修改的默认文件。
我有一个厨师食谱来创建部署用户。 运行 kitchen converge
时正在创建用户。尝试为用户创建 .ssh
文件夹时失败,因为用户的主目录不存在。 Parent directory /home/deploy does not exist, cannot create /home/deploy/.ssh
。
cookbooks/main/recipes/user.rb
user deploy do
action :create
comment 'Application deploy user'
home "/home/#{node['deploy_user']}"
shell '/bin/bash'
system true
supports manage_home: true
end
directory "/home/#{node['deploy_user']}/.ssh" do
mode 0700
owner node['deploy_user']
group node['deploy_user']
end
template "/home/#{node['deploy_user']}/.ssh/authorized_keys" do
mode 0600
owner node['deploy_user']
source 'authorized_keys.erb'
end
.kitchen.yml
---
driver:
name: vagrant
provisioner:
name: chef_solo
platforms:
- name: ubuntu-14.04
- name: centos-7.1
suites:
- name: default
run_list:
- recipe[main::default]
attributes:
您将 deploy
传递给用户资源名称而不是 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
来自man useradd
:
-r, --system
Create a system account.
System users will be created with no aging information in /etc/shadow, and their numeric identifiers are choosen 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.
或者简而言之,将 manage_home true
添加到您的资源中。
可能是运行顺序问题。尝试
user node['deploy_user'] do
comment 'Application deploy user'
home "/home/#{node['deploy_user']}"
shell '/bin/bash'
system true
manage_home true
end.run_action(:create)
这也激怒了我。大厨没有理由不让这么简单的日常动作变得容易执行。
由于这是 google 的热门搜索,我不清楚其他答案是否正确,这正是我 运行 需要的答案。我正在使用厨师服务器 12.4 和客户端 12.10.24。全部在 Ubuntu 14.04.
user '<USERNAME>' do
gid '<MY_GROUP_NAME>'
shell '/bin/bash'
comment 'some stuff i want to say'
home "/home/<USERNAME>"
supports manage_home: true
action :create
end
我的/etc/login.defs 文件是未修改的默认文件。