toquen 0.2.7 → 1.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: 37992871b208407c2654c023d1aa5c170c606310
4
- data.tar.gz: 525c9bd60e41fab5593654aad4decaaea0127937
3
+ metadata.gz: 579e6f22363537bfbfb76e7f656af174e30aae2a
4
+ data.tar.gz: 511050a12e16cf24c25e73b1a4b31d4d96f39ac7
5
5
  SHA512:
6
- metadata.gz: 7620d4539651e18d663093bb27c7e51d2514a3bed656f0dc4c6005f6a63a022d4c8d74389f9cc7ee748adfb32832e315ec8e809fc3416e4508247fb035ecc319
7
- data.tar.gz: 2454c2e59f8a6677877bb8f8c3c6a1aa6cb57e18cbd13aa233fad5bdd8d7b31aa841656ab12bc8956048e28a9ef0f0fd5976c49f58ac57703128774c81364574
6
+ metadata.gz: 7d44a635acd6dd55c8fdfbc9ccb9f19e2f046423d543df0b5b8e6884094f0cd29299873789fb23327371766e27715c911109648410a8d8d3f56b75f51cde6d56
7
+ data.tar.gz: 8e227a65db4d5f382583377a737e2ad112b336396d62607ca715032e9d4da1d4a985645b50f3ad201321a3690c9639c728fc25e36da155c1f754469599d19ce3
data/README.md CHANGED
@@ -26,9 +26,9 @@ bundle
26
26
  cap toquen_install
27
27
  ```
28
28
 
29
- This will create a config directory with a file named *deploy.rb*. Edit this file, setting the location of your AWS key, AWS credentials, and chef cookbooks/data bags/roles. If your servers are in a region (or regions) other than us-east-1, then you'll need to set the region as [described below](#additional-configuration).
29
+ This will create a config directory with a file named *deploy.rb*. Edit this file, setting the location of your AWS key, AWS credentials, and chef cookbooks/data bags/roles/environments. If your servers are in a region (or regions) other than us-east-1, then you'll need to set the region as [described below](#additional-configuration).
30
30
 
31
- Then, in AWS, create an [AWS instance tag](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) named "Roles" for each instance, using a space separated list of chef roles as the value. The "Name" tag must also be set or the instance will be ignored.
31
+ Then, in AWS, create an [AWS instance tag](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) named "Roles" for each instance, using a space separated list of chef roles as the value. The "Name" tag must also be set or the instance will be ignored. You can optionally set an "Environment" tag as well if you'd like chef [to use an environment](https://docs.chef.io/environments.html) for that server.
32
32
 
33
33
  Then, run:
34
34
 
@@ -167,8 +167,8 @@ cap databases open_ssh cook close_ssh
167
167
  Toquen can also drop off a config file meant for use by applications on your system. Here's how that works:
168
168
 
169
169
  1. Toquen creates a hash that contains a list of all of your servers and all of their details (based on your servers data_bag)
170
- 1. Toquen looks for a file named "apps.json" in your config folder, and if it's found, Toquen pulls out all of the keys that correspond with the server's roles and merges them together with the hash it's building (if this file contains secrets, consider *not* including in revision control)
171
- 1. The resulting hash is dropped off in your user's home directory (this can be overridden with the apps_config_path config variable) with the filename "apps.json".
170
+ 1. Toquen looks for a file named "apps.json" in your config folder, and if it's found, Toquen pulls out all of the keys that correspond with the server's roles and environments, and then it merges them together with the hash it's building (if this file contains secrets, consider *not* including in revision control)
171
+ 1. The resulting hash is dropped off in your user's home directory (this can be overridden with the `apps_config_path` config variable) with the filename "apps.json".
172
172
 
173
173
  Most likely, you'll want to add this line to your deploy.rb:
174
174
 
@@ -104,7 +104,8 @@ module Toquen
104
104
  :type => i.instance_type,
105
105
  :external_dns => i.public_dns_name,
106
106
  :internal_dns => i.private_dns_name,
107
- :security_groups => i.security_groups.to_a.map(&:id)
107
+ :security_groups => i.security_groups.to_a.map(&:id),
108
+ :environment => i.tags["Environment"] || nil
108
109
  }
109
110
  end
110
111
  end
@@ -63,6 +63,9 @@ task :update_appconfig do
63
63
  host.properties.roles.each do |role|
64
64
  appconfig.merge!(apps[role.to_s] || {})
65
65
  end
66
+ if host.properties.environment
67
+ appconfig.merge!(apps[host.properties.environment.to_s] || {})
68
+ end
66
69
  debug "Uploading app config file to #{dest}"
67
70
  upload! StringIO.new(JSON.pretty_generate(appconfig)), "/tmp/apps.json"
68
71
  sudo "mv /tmp/apps.json #{dest}"
@@ -95,12 +98,13 @@ task :update_kitchen do
95
98
  run_locally do
96
99
  info "Building kitchen locally..."
97
100
  execute [
98
- "rm -rf #{lkitchen}",
99
- "mkdir -p #{lkitchen}",
100
- "ln -s #{File.expand_path(fetch(:chef_cookbooks_path))} #{lkitchen}",
101
- "ln -s #{File.expand_path(fetch(:chef_data_bags_path))} #{lkitchen}",
102
- "ln -s #{File.expand_path(fetch(:chef_roles_path))} #{lkitchen}"
103
- ].join(" && ")
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(" && ")
104
108
  end
105
109
 
106
110
  open("#{lkitchen}/chef_config.rb", 'w') { |f|
@@ -124,13 +128,17 @@ desc "Run chef for servers"
124
128
  task :cook do
125
129
  on roles(:all), in: :parallel do |host|
126
130
  info "Chef is now cooking on #{host}..."
131
+ env = host.properties.environment
127
132
  roles = host.properties.roles.reject { |r| r.to_s.start_with?('server-') or r == :all }
128
133
  roles = roles.map { |r| "\"role[#{r}]\"" }.join(',')
129
134
  info "Roles for #{host}: #{roles}"
130
135
  tfile = "chef.json"
131
136
  upload! StringIO.new("{ \"run_list\": [ #{roles} ] }"), tfile
132
137
  within fetch(:chef_upload_location) do
133
- execute "sudo chef-solo -c #{fetch(:chef_upload_location)}/kitchen/chef_config.rb -j #{tfile}"
138
+ args = ["-c #{fetch(:chef_upload_location)}/kitchen/chef_config.rb"]
139
+ args += ["-j #{tfile}"]
140
+ args += ["--environment #{env}"] unless env.nil?
141
+ execute "sudo chef-solo #{args.join(' ')}"
134
142
  end
135
143
  end
136
144
  end
@@ -19,7 +19,7 @@ module Toquen
19
19
  }
20
20
  )
21
21
  table.title = @color.bold { "Instances in #{@region}" }
22
- header = [ "Name", "Roles", "Public", "Private", "Type" ]
22
+ header = [ "Name", "Roles", "Env", "Public", "Private", "Type" ]
23
23
  table.add_row header.map { |h| @color.underline @color.bold h }
24
24
  @instances.each do |instance|
25
25
  table.add_row instance_to_row(instance)
@@ -31,6 +31,7 @@ module Toquen
31
31
  [
32
32
  @color.green { instance[:name] },
33
33
  @color.yellow { instance[:roles].join(",") },
34
+ @color.magenta { instance[:environment] || "" },
34
35
  instance[:external_dns].nil? ? "(N/A)" : @color.cyan(instance[:external_dns]) + " (#{instance[:external_ip]})",
35
36
  instance[:internal_dns].nil? ? "(N/A)" : @color.cyan(instance[:internal_dns]) + " (#{instance[:internal_ip]})",
36
37
  @color.red { instance[:type] }
@@ -16,7 +16,10 @@ module Toquen
16
16
  secgroups = []
17
17
  servers.each { |details|
18
18
  rstring = (details[:roles] + [ "all", "server-#{details[:name]}" ]).join(' ')
19
- f.write("server '#{details[:external_ip]}', roles: %w{#{rstring}}, awsname: '#{details[:name]}'\n")
19
+ f.write("server '#{details[:external_ip]}', ")
20
+ f.write("roles: %w{#{rstring}}, ")
21
+ f.write("environment: \"#{details[:environment]}\", ") unless details[:environment].nil?
22
+ f.write("awsname: '#{details[:name]}'\n")
20
23
  secgroups += details[:security_groups]
21
24
  }
22
25
  secstring = secgroups.uniq.join(' ')
@@ -13,3 +13,6 @@ set :ssh_options, { :keys => ["./mykey.pem"], :user => "ubuntu" }
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
+
17
+ # this directory should exist, even if empty
18
+ set :chef_environments_path, 'kitchen/environment'
@@ -1,3 +1,3 @@
1
1
  module Toquen
2
- VERSION = "0.2.7"
2
+ VERSION = "1.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: 0.2.7
4
+ version: 1.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-09 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano