I'm using chef to create a file resource
file "somefile" do
action :create_if_missing
end
And I want to put this in the user's home directory. I am having two issues:
node[:user]
appears to be empty.Is there a way to create a file in the non-root user (in this case vagrant) home directory?
Thread is old, but I faced this problem a moment ago.
You can create attribute for user for example: default['mycookbook']['user']
Then in your recipe:
user = node['mycookbook']['user'] # user set in cookbook attrubute
# user = node['current_user'] # user running chef cookbook (on provisioned host)
home = node['etc']['passwd'][user]['dir'] # Chef DSL
# home = Dir.home(user) # It's Ruby
file "#{home}/somefile" do
action :create_if_missing
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With