Chef不为用户创建主目录

时间:2016-01-05 19:18:09

标签: chef chef-recipe chef-solo test-kitchen

我有一个厨师食谱来创建部署用户。运行kitchen converge时正在创建用户。尝试为用户创建.ssh文件夹时失败,因为该用户的主目录不存在。 Parent directory /home/deploy does not exist, cannot create /home/deploy/.ssh

食谱/主/食谱/ 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:

4 个答案:

答案 0 :(得分:2)

这也激怒了我。没有理由让厨师不要轻易做出这么简单的例行动作。

由于这是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文件是未修改的默认值。

答案 1 :(得分:0)

您已将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

答案 2 :(得分:0)

来自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添加到您的资源中。

答案 3 :(得分:0)

也许是运行顺序问题。尝试

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)