【问题标题】:Chef doesn't create home directory for user厨师不会为用户创建主目录
【发布时间】:2016-10-26 09:12:48
【问题描述】:

我有一个厨师食谱来创建一个部署用户。运行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:

【问题讨论】:

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


    【解决方案1】:

    这也激怒了我。 Chef 没有理由不让如此简单的日常动作变得容易执行。

    由于这是一个顶级谷歌搜索,我不清楚其他答案是否正确,这正是我需要运行以使其工作的内容。我正在使用厨师服务器 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 文件是未修改的默认文件。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 代码对我来说似乎是正确的。也许错误在其他地方,可能吗?
      【解决方案3】:

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

      【讨论】:

      • 我试过 manage_home truesupports manage_home: true 都不起作用。
      • 使用-l debug 运行并检查最终运行的命令。一般来说,如果你想要一个主目录和其他类似用户的行为,你不应该使用system true
      • 调试很长。我不确定要寻找什么。
      • 您正在寻找正在运行的命令来创建用户。
      • 我看到的都是Recipe: main::user * user[deploy] action create[2016-01-05T22:10:52+00:00] INFO: Processing user[deploy] action create (main::user line 1) [2016-01-05T22:10:52+00:00] DEBUG: Providers for generic user resource enabled on node include: [Chef::Provider::User::Useradd] [2016-01-05T22:10:52+00:00] DEBUG: Provider for action create on resource user[deploy] is Chef::Provider::User::Useradd
      【解决方案4】:

      可能是运行顺序问题。试试

      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)
      

      【讨论】:

        猜你喜欢
        • 2012-10-03
        • 2014-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-17
        • 1970-01-01
        相关资源
        最近更新 更多