Search code examples
chef-infrachef-recipechef-solotest-kitchen

Chef doesn't create home directory for user


I have a chef recipe to create a deploy user. The user is being created when running kitchen converge. When trying to create the .ssh folder for the user it fails with because the home directory for the user does not exists. 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:

Solution

  • 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