Commit 5b92b27

mo khan <mo@mokhan.ca>
2015-05-04 03:17:13
add aws recipe and fix foodcritic violations.
1 parent f5ece28
attributes/default.rb
@@ -41,14 +41,14 @@ default['capistrano']['env'] = {
   },
   newrelic_key: '',
 }
-default[:delayed_job][:username] = node['user']['username']
-default[:delayed_job][:current_path] = "#{node['capistrano']['root_path']}/current"
-default[:delayed_job][:rails_env] = node.chef_environment
-default[:nginx][:domain] = 'www.example.com'
-default[:nginx][:current_path] = "#{node['capistrano']['root_path']}/current"
-default[:nginx][:shared_path] = "#{node['capistrano']['root_path']}/shared_path"
-default[:unicorn][:username] = node['user']['username']
-default[:unicorn][:current_path] = "#{node['capistrano']['root_path']}/current"
-default[:unicorn][:rails_env] = node.chef_environment
-default[:monit][:application] = 'app'
+default['delayed_job']['username'] = node['user']['username']
+default['delayed_job']['current_path'] = "#{node['capistrano']['root_path']}/current"
+default['delayed_job']['rails_env'] = node.chef_environment
+default['nginx']['domain'] = 'www.example.com'
+default['nginx']['current_path'] = "#{node['capistrano']['root_path']}/current"
+default['nginx']['shared_path'] = "#{node['capistrano']['root_path']}/shared_path"
+default['unicorn']['username'] = node['user']['username']
+default['unicorn']['current_path'] = "#{node['capistrano']['root_path']}/current"
+default['unicorn']['rails_env'] = node.chef_environment
+default['monit']['application'] = 'app'
 default['rbenv']['ruby_version'] = '2.2.0'
recipes/aws.rb
@@ -0,0 +1,29 @@
+include_recipe "apt"
+configuration = node['aws']
+
+package 'python-pip' do
+  action :install
+end
+
+execute 'install awscli' do
+  command 'pip install awscli'
+  action :run
+end
+
+directory "/home/#{configuration["username"]}/.aws/" do
+  owner configuration['username']
+  group configuration['username']
+  mode "0755"
+  recursive true
+  action :create
+end
+
+template "/home/#{configuration["username"]}/.aws/config" do
+  source "aws/config.erb"
+  variables(configuration)
+end
+
+template "/home/#{configuration["username"]}/.aws/credentials" do
+  source "aws/credentials.erb"
+  variables(configuration)
+end
recipes/default.rb
@@ -1,4 +1,6 @@
 include_recipe "apt"
+include_recipe "mokhan-myface::user"
+include_recipe "mokhan-myface::aws"
 include_recipe "mokhan-myface::monit"
 
 packages = [
recipes/nginx.rb
@@ -12,7 +12,7 @@ package 'nginx' do
 end
 package 'logrotate'
 
-configuration = node[:nginx]
+configuration = node['nginx']
 directory "/etc/nginx/ssl" do
   owner "root"
   group "root"
@@ -20,7 +20,7 @@ directory "/etc/nginx/ssl" do
   action :create
 end
 
-cookbook_file "/etc/nginx/ssl/#{configuration[:domain]}.crt" do
+cookbook_file "/etc/nginx/ssl/#{configuration['domain']}.crt" do
   source "#{node.chef_environment}.crt"
   mode "0644"
 end
recipes/unicorn.rb
@@ -1,4 +1,4 @@
-configuration = node[:unicorn]
+configuration = node['unicorn']
 
 template "/etc/init.d/unicorn" do
   source "unicorn.erb"
spec/aws_spec.rb
@@ -0,0 +1,25 @@
+describe "mokhan-myface::aws" do
+  subject do
+    ChefSpec::SoloRunner.new do |node|
+      node.set['aws']['username'] = username
+    end.converge(described_recipe)
+  end
+
+  let(:username) { FFaker::Internet.user_name }
+
+  it 'installs python-ip' do
+    expect(subject).to install_package('python-pip')
+  end
+
+  it 'installs awscli' do
+    expect(subject).to run_execute('pip install awscli')
+  end
+
+  it 'installs the config file' do
+    expect(subject).to create_template("/home/#{username}/.aws/config")
+  end
+
+  it 'installs the credentials file' do
+    expect(subject).to create_template("/home/#{username}/.aws/credentials")
+  end
+end
templates/default/aws/config.erb
@@ -0,0 +1,6 @@
+<% @profiles.each do |profile, options|
+[profile <%= profile %>]
+  <% options.each do |key, value| %>
+<%= key %> = <%= value %>
+  <% end %>
+<% end %>
templates/default/aws/credentials.erb
@@ -0,0 +1,6 @@
+<% @profiles.each do |profile, options|
+[profile <%= profile %>]
+<% options.each do |key, value| %>
+  <%= key %> = <%= value %>
+<% end %>
+<% end %>