toquen 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8703dab7d98090f0909462f56db13a6c0a84fd7e
4
- data.tar.gz: a33ae98ea6f1d5608a26aee39e5852617d2e169f
3
+ metadata.gz: 03245820adba3a998f96cd66ced0c2a9613b891a
4
+ data.tar.gz: 3794fb563b8e172655e5d3829de4dd4c78c8fb3f
5
5
  SHA512:
6
- metadata.gz: 8c7d68c25b2793422379e67c9e0e371648346d207eb51da1a868c796be3e755eac8b9a4f293feb3725c7001d929c057368d98eab35d75b0754a51222153897bf
7
- data.tar.gz: 1595de9ad4cabcbe322cdf0dde7dc100731cff11fdceba38311d2146fa12704ffb03a8987bbe8494b10592cfc3d046a08ca3b95420ce6bc712c411c45ee42a35
6
+ metadata.gz: b06c9e073d2cbd3dad11ab8525e946a9e6196819e43b199cf386187026f5b4c763029dc47c018cb798a72d1c33fcd6455f5ffab361b4aa029c331a23a26a142c
7
+ data.tar.gz: 91ff2004da7c0c5c2422acbc0dab97f6bcca2a58ba77e6839dd530dba7ac5175476bcd1d8a689cbfbcf5f8b9faa2d516c846ae671b650f16d06642832cc70aeb
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Toquen
2
2
  ![A Toque](http://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/William_Orpen_Le_Chef_de_l%27H%C3%B4tel_Chatham%2C_Paris.jpg/97px-William_Orpen_Le_Chef_de_l%27H%C3%B4tel_Chatham%2C_Paris.jpg)
3
3
 
4
- **Toquen** combines [Capistrano 3](http://www.capistranorb.com), [Chef](http://www.getchef.com), and [AWS instance tags](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) into one bundle of joy. Instance roles are stored in AWS tags and **Toquen** can suck those out, put them into data bags for chef, and create stages in capistrano. You can then selectively run chef on individual servers or whole roles that contain many servers with simple commands.
4
+ **Toquen** combines [Capistrano 3](http://www.capistranorb.com), [Chef](http://www.getchef.com), and [AWS instance tags](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) into one bundle of joy. Instance roles are stored in AWS tags and **Toquen** can suck those out, put them into node descriptions for chef, and create stages in capistrano. You can then selectively run chef on individual servers or whole roles that contain many servers with simple commands.
5
5
 
6
6
  ## Installation
7
- Before beginning, you should already understand how [chef-solo](http://docs.opscode.com/chef_solo.html) works and have some cookbooks, roles defined, and at least a folder for data_bags (even if it's empty). The rest of this guide assumes you have these ready as well as an AWS PEM key and [access credentials](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html).
7
+ Before beginning, you should already understand how [chef](https://docs.chef.io) works and have some cookbooks, roles defined, and at least a folder for data_bags (even if it's empty). Toquen uses the chef-client in [local mode](https://docs.chef.io/ctl_chef_client.html#run-in-local-mode), which is worth understanding before diving into Toquen. The rest of this guide assumes you have these ready as well as an AWS PEM key and [access credentials](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html).
8
8
 
9
9
  Generally, it's easiest if you start off in an empty directory. First, create a file named *Gemfile* that contains these lines:
10
10
 
@@ -33,10 +33,10 @@ Then, in AWS, create an [AWS instance tag](http://docs.aws.amazon.com/AWSEC2/lat
33
33
  Then, run:
34
34
 
35
35
  ```shell
36
- cap update_roles
36
+ cap update_nodes
37
37
  ```
38
38
 
39
- This will create a data_bag named *servers* in your data_bags path that contains one item per server name, as well as create stages per server and role for use in capistrano.
39
+ This will write server information from AWS to [chef node](https://docs.chef.io/nodes.html) files and will create stages per server and role for use in capistrano. By writing server information to node files, you'll be able to use [search](https://docs.chef.io/chef_search.html) in your recipes, allowing you to reference other nodes' locations and other metadata.
40
40
 
41
41
  ## Server Bootstrapping
42
42
  Bootstrapping a server will perform all of the following:
@@ -67,8 +67,8 @@ cap all bootstrap
67
67
 
68
68
  A lockfile is created after the first bootstrapping so that the full bootstrap process is only run once per server.
69
69
 
70
- ## Running Chef-Solo
71
- You can run chef-solo for a single server by using:
70
+ ## Running the Chef Client
71
+ You can run chef for a single server by using:
72
72
 
73
73
  ```shell
74
74
  cap server-<server name> cook
@@ -86,14 +86,14 @@ Or on all servers:
86
86
  cap all cook
87
87
  ```
88
88
 
89
- ## Updating Roles
90
- If you change the roles of any servers on AWS (or add any new ones) you will need to run:
89
+ ## Updating Node Information
90
+ If you change the roles (or any other metadata / ip addresses / etc) for any servers on AWS (or add any new ones) you will need to run:
91
91
 
92
92
  ```shell
93
- cap update_roles
93
+ cap update_nodes
94
94
  ```
95
95
 
96
- This will update the *servers* data_bag as well as the capistrano stages.
96
+ This will update the local node information cache as well as the capistrano stages.
97
97
 
98
98
  ## Additional Configuration
99
99
  If you want to use a different tag name (or you like commas as a delimiter) you can specify your own role extractor/setter by placing the following in either your Capfile or config/deploy.rb:
@@ -5,8 +5,8 @@ require 'json'
5
5
 
6
6
  set :chef_upload_location, -> { "/home/#{fetch(:ssh_options)[:user]}" }
7
7
 
8
- desc "update local cache of servers and roles"
9
- task :update_roles do
8
+ desc "update local cache of nodes and roles"
9
+ task :update_nodes do
10
10
  load Pathname.new fetch(:deploy_config_path, 'config/deploy.rb')
11
11
  roles = Hash.new([])
12
12
  servers = []
@@ -15,7 +15,7 @@ task :update_roles do
15
15
  aws.server_details.each do |details|
16
16
  details[:roles].each { |role| roles[role] += [details] }
17
17
  roles['all'] += [details]
18
- Toquen::LocalWriter.create_databag_item details
18
+ Toquen::LocalWriter.create_node details
19
19
  Toquen::LocalWriter.create_stage "server-#{details[:name]}", [details]
20
20
  servers << details[:name]
21
21
  end
@@ -97,22 +97,23 @@ task :update_kitchen do
97
97
 
98
98
  run_locally do
99
99
  info "Building kitchen locally..."
100
- execute [
101
- "rm -rf #{lkitchen}",
102
- "mkdir -p #{lkitchen}",
103
- "ln -s #{File.expand_path(fetch(:chef_cookbooks_path))} #{lkitchen}",
104
- "ln -s #{File.expand_path(fetch(:chef_data_bags_path))} #{lkitchen}",
105
- "ln -s #{File.expand_path(fetch(:chef_roles_path))} #{lkitchen}",
106
- "ln -s #{File.expand_path(fetch(:chef_environments_path))} #{lkitchen}"
107
- ].join(" && ")
100
+ execute :rm, "-rf", lkitchen
101
+ execute :mkdir, "-p", lkitchen
102
+ %W(cookbooks data_bags roles environments nodes).each do |dname|
103
+ source = File.expand_path fetch("chef_#{dname}_path".intern)
104
+ execute :ln, "-s", source, File.join(lkitchen, dname)
105
+ end
108
106
  end
109
107
 
110
108
  open("#{lkitchen}/chef_config.rb", 'w') { |f|
111
- f.write("file_cache_path '/var/chef-solo'\n")
112
109
  f.write("cookbook_path '#{kitchen}/cookbooks'\n")
113
- f.write("data_bag_path '#{kitchen}/data_bags'\n")
114
110
  f.write("role_path '#{kitchen}/roles'\n")
115
- f.write("ssl_verify_mode :verify_peer\n")
111
+ f.write("data_bag_path '#{kitchen}/data_bags'\n")
112
+ f.write("environment_path '#{kitchen}/environments'\n")
113
+ f.write("node_path '#{kitchen}/nodes'\n")
114
+ f.write("log_level :#{fetch(:chef_log_level)}\n")
115
+ f.write("cache_path '/tmp/chef_cache'\n")
116
+ f.write("local_mode 'true'\n")
116
117
  }
117
118
 
118
119
  on roles(:all), in: :parallel do |host|
@@ -129,17 +130,9 @@ desc "Run chef for servers"
129
130
  task :cook do
130
131
  on roles(:all), in: :parallel do |host|
131
132
  info "Chef is now cooking on #{host}..."
132
- env = host.properties.environment
133
- roles = host.properties.roles.reject { |r| r.to_s.start_with?('server-') or r == :all }
134
- roles = roles.map { |r| "\"role[#{r}]\"" }.join(',')
135
- info "Roles for #{host}: #{roles}"
136
- tfile = "chef.json"
137
- upload! StringIO.new("{ \"run_list\": [ #{roles} ] }"), tfile
138
133
  within fetch(:chef_upload_location) do
139
- args = ["-c #{fetch(:chef_upload_location)}/kitchen/chef_config.rb"]
140
- args += ["-j #{tfile}"]
141
- args += ["--environment #{env}"] unless env.nil?
142
- execute "sudo chef-solo #{args.join(' ')}"
134
+ config = "#{fetch(:chef_upload_location)}/kitchen/chef_config.rb"
135
+ execute "sudo chef-client -c #{config}"
143
136
  end
144
137
  end
145
138
  end
@@ -256,7 +249,7 @@ module Capistrano
256
249
  module TaskEnhancements
257
250
  alias_method :original_default_tasks, :default_tasks
258
251
  def default_tasks
259
- original_default_tasks + %w{toquen_install update_roles}
252
+ original_default_tasks + %w{toquen_install update_nodes}
260
253
  end
261
254
  end
262
255
  end
@@ -1,10 +1,17 @@
1
1
  module Toquen
2
2
  module LocalWriter
3
- def self.create_databag_item(details)
4
- servers = "#{fetch(:chef_data_bags_path)}/servers"
5
- FileUtils.mkdir_p servers
6
- open("#{servers}/#{details[:name]}.json", 'w') do |f|
7
- f.write JSON.dump(details)
3
+ def self.create_node(details)
4
+ FileUtils.mkdir_p fetch(:chef_nodes_path)
5
+ path = File.join(fetch(:chef_nodes_path), "#{details[:name]}.json")
6
+ existing = File.exists?(path) ? JSON.parse(File.read(path)) : {}
7
+ open(path, 'w') do |f|
8
+ node = {
9
+ name: details[:name],
10
+ chef_environment: details[:environment],
11
+ normal: { toquen: details },
12
+ run_list: details[:roles].map { |r| "role[#{r}]" }
13
+ }.merge(existing)
14
+ f.write JSON.pretty_generate(node)
8
15
  end
9
16
  end
10
17
 
@@ -9,10 +9,14 @@ set :aws_secret_access_key, nil
9
9
  # each server.
10
10
  set :ssh_options, { :keys => ["./mykey.pem"], :user => "ubuntu" }
11
11
 
12
- # Set the location of your cookbooks/data bags/roles for Chef
12
+ # Set the location of your cookbooks/data bags/roles/nodes for Chef
13
13
  set :chef_cookbooks_path, 'kitchen/cookbooks'
14
14
  set :chef_data_bags_path, 'kitchen/data_bags'
15
15
  set :chef_roles_path, 'kitchen/roles'
16
+ set :chef_nodes_path, 'kitchen/nodes'
16
17
 
17
18
  # this directory should exist, even if empty
18
19
  set :chef_environments_path, 'kitchen/environment'
20
+
21
+ # log level for chef
22
+ set :chef_log_level, :warn
@@ -12,9 +12,12 @@ DEBIAN_FRONTEND=noninteractive
12
12
  apt-get -y update && apt-get -y install software-properties-common
13
13
  apt-add-repository -y ppa:brightbox/ruby-ng
14
14
 
15
- # update apt, install ruby 2.3, upgrade everything
15
+ # update apt, install ruby 2.2, upgrade everything
16
+ # note: ruby2.3 is available, but shouldn't be installed
17
+ # until https://github.com/chef/chef/issues/4359 gets
18
+ # into a release version.
16
19
  apt-get -y update
17
- apt-get -y install build-essential ruby2.3 ruby2.3-dev
20
+ apt-get -y install build-essential ruby2.2 ruby2.2-dev
18
21
  apt-get -y upgrade && apt-get -y dist-upgrade
19
22
 
20
23
  # install chef
@@ -1,3 +1,3 @@
1
1
  module Toquen
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toquen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Muller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano