Created
June 17, 2013 10:04
-
-
Save shinyay/5795911 to your computer and use it in GitHub Desktop.
my-users default recipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user = Chef::EncryptedDataBagItem.load("users", 'deploy') | |
| user_name = user['name'] | |
| password = user['password'] | |
| ssh_key = user['ssh_key'] | |
| home = "/home/#{user_name}" | |
| # Create a User [deploy] | |
| user user_name do | |
| password password | |
| home home | |
| shell "/bin/bash" | |
| supports :manage_home => true # Manage home directory | |
| end | |
| # Add [deploy] to [wheel]group | |
| group "wheel" do | |
| action [:modify] | |
| members [user_name] | |
| append true | |
| end | |
| # Create .ssh directory | |
| directory "#{home}/.ssh" do | |
| owner user_name | |
| group user_name | |
| end | |
| # create an authorized_keys file | |
| authorized_keys_file ="#{home}/.ssh/authorized_keys" | |
| file authorized_keys_file do | |
| owner user_name | |
| mode 0600 | |
| content "#{ssh_key} #{user_name}" | |
| not_if { ::File.exists?("#{authorized_keys_file}")} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment