Permalink
Browse files

Added dotfiles and authorized cookbooks

  • Loading branch information...
1 parent 31e0f77 commit 8b765ab59a35ad84674e75eda6965a0f2baad6b2 @flashingpumpkin flashingpumpkin committed Dec 1, 2011
View
@@ -76,3 +76,37 @@ control services you're deploying.
The process will automatically create a `/var/log/<username>/<process-name>.log`
file owned by the specified user - a bit like foreman does.
+## dotfiles
+
+Useful dotfiles to have around. For now it's only a `.pythonrc` file so your
+Python sessions remember what you've been doing.
+
+* Usage:
+
+ cookbook_file "/etc/profile.d/pythonrc.sh" do
+ source "profile.d/pythonrc.sh"
+ cookbook "dotfiles"
+ owner "root"
+ end
+ cookbook_file "/home/user/.pythonrc.py" do
+ source "home/.pythonrc.py"
+ cookbook "dotfiles"
+ owner "user"
+ end
+
+
+## authorized
+
+Deploy your public SSH keys for passwordless authentication on the server.
+
+* Usage:
+
+ keys = ["ssh-rsa ...", "ssh-rsa ..."]
+ authorized_keys "your-user" do
+ keys keys
+ homeroot "/home"
+ end
+ authorized_keys "root" do
+ keys keys
+ homeroot "/"
+ end
@@ -0,0 +1,44 @@
+require 'chef/mixin/shell_out'
+require 'chef/mixin/language'
+include Chef::Mixin::ShellOut
+
+action :create do
+ Chef::Log.info("Adding authorized SSH keys to #{@new_resource.user}")
+ save_keys @new_resource
+end
+
+action :delete do
+ if exists?
+ delete_keys @new_resource
+ end
+end
+
+action :create_if_missing do
+ unless exists?
+ save_keys @new_resource
+ end
+end
+
+private
+def save_keys(resource)
+ directory "#{resource.homeroot}/#{resource.user}/.ssh" do
+ owner resource.user
+ mode 0700
+ action: create
+ end
+ template "#{resource.homeroot}/#{resource.user}/.ssh/authorized_keys" do
+ cookbook "authorized"
+ source "authorized_keys.erb"
+ mode 0600
+ variables (:keys => resource.keys)
+ end
+end
+
+private
+def delete_keys
+ ::File.delete("#{resource.homeroot}/#{@new_resource.user}/.ssh/authorized_keys")
+end
+
+private
+def exists?
+ ::File.exists?("#{resource.homeroot}/#{@new_resource.user}/.ssh/authorized_keys")
@@ -0,0 +1,9 @@
+actions :create, :delete, :create_if_missing
+
+attribute :user, :kind_of => String, :name_attribute => true
+attribute :keys
+attribute :homeroot, :kind_of => String, :default => "/home"
+
+def initialize(*args)
+ super
+ @action = :create
@@ -0,0 +1,3 @@
+<% @keys.each do |key| %>
+<%= key %>
+<% end %>
@@ -0,0 +1 @@
+[ -f ~/.pythonrc.py ] && PYTHONSTARTUP=~/.pythonrc.py

0 comments on commit 8b765ab

Please sign in to comment.