toquen 0.1.6 → 0.1.7

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: fc919b62baa61b77c95fbc37adb7cf5dd605c191
4
- data.tar.gz: 36e39c1a7c4e05714e158bce508cc6e14ec820f1
3
+ metadata.gz: 34b63993bc1126c81404fbe874d89914614bfff5
4
+ data.tar.gz: c4d2634dc32e3c8536bbc23b0b897c8a743aedbd
5
5
  SHA512:
6
- metadata.gz: 7d16f37d4d3b0ba4f707921b76b3cd82270ed65cdfcac00bae9814cbd2bd48b7a0a14e1bbf91cf91aa72fa60af57c2827e4e5004695257f15cd3a839bbec6d9c
7
- data.tar.gz: a9228618e4e6a0e0683505e35a1d80fd6f7924302430046b45de959e6bc430ddd75eb16df366981609c536ed183d274fa37c4f68b6c89c77acd123d08cec8406
6
+ metadata.gz: e33a6a39783554076024a8aa06d90aaf967c1928c42e05441316524592565db98f63def6bbc8872b4c8f7f5abc1b93e72291750d09c88be7af0e4907d07fd36f
7
+ data.tar.gz: e3ec4ce94543cf174ecbd00cfb7e938b44167952d46dec9edc147ff9c3f878c5280d521427b9add8afd173c682e1c82ae6c076a1fd78c61698479bd785e8efc7
data/README.md CHANGED
@@ -21,8 +21,10 @@ require 'toquen'
21
21
 
22
22
  And then on the command line execute:
23
23
 
24
- $ bundle
25
- $ cap toquen_install
24
+ ```shell
25
+ bundle
26
+ cap toquen_install
27
+ ```
26
28
 
27
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).
28
30
 
@@ -30,7 +32,9 @@ Then, in AWS, create an [AWS instance tag](http://docs.aws.amazon.com/AWSEC2/lat
30
32
 
31
33
  Then, run:
32
34
 
33
- $ cap update_roles
35
+ ```shell
36
+ cap update_roles
37
+ ```
34
38
 
35
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.
36
40
 
@@ -45,43 +49,59 @@ Bootstrapping a server will perform all of the following:
45
49
 
46
50
  You can bootstrap a single server by using:
47
51
 
48
- $ cap server-<server name> bootstrap
52
+ ```shell
53
+ cap server-<server name> bootstrap
54
+ ```
49
55
 
50
56
  Or a all the servers with a given role:
51
57
 
52
- $ cap <role name> bootstrap
58
+ ```shell
59
+ cap <role name> bootstrap
60
+ ```
53
61
 
54
62
  Or on all servers:
55
63
 
56
- $ cap all bootstrap
64
+ ```shell
65
+ cap all bootstrap
66
+ ```
57
67
 
58
68
  A lockfile is created after the first bootstrapping so that the full bootstrap process is only run once per server.
59
69
 
60
70
  ## Running Chef-Solo
61
71
  You can run chef-solo for a single server by using:
62
72
 
63
- $ cap server-<server name> cook
73
+ ```shell
74
+ cap server-<server name> cook
75
+ ```
64
76
 
65
77
  Or a all the servers with a given role with:
66
78
 
67
- $ cap <role name> cook
79
+ ```shell
80
+ cap <role name> cook
81
+ ```
68
82
 
69
83
  Or on all servers:
70
84
 
71
- $ cap all cook
85
+ ```shell
86
+ cap all cook
87
+ ```
72
88
 
73
89
  ## Updating Roles
74
90
  If you change the roles of any servers on AWS (or add any new ones) you will need to run:
75
91
 
76
- $ cap update_roles
92
+ ```shell
93
+ cap update_roles
94
+ ```
77
95
 
78
96
  This will update the *servers* data_bag as well as the capistrano stages.
79
97
 
80
98
  ## Additional Configuration
81
- If you want to use a different tag name (or you like commas as a delimiter) you can specify your own role extractor by placing the following in either your Capfile or config/deploy.rb:
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:
82
100
 
83
101
  ```ruby
102
+ # these are the default - replace with your own
84
103
  Toquen.config.aws_roles_extractor = lambda { |inst| (inst.tags["MyRoles"] || "").split(",") }
104
+ Toquen.config.aws_roles_setter = lambda { |ec2, inst, roles| ec2.tags.create(inst, 'Roles', :value => roles.sort.join(' ')) }
85
105
  ```
86
106
 
87
107
  By default, instance information is only pulled out of the default region (us-east-1), but you can specify mutiple alternative regions:
@@ -99,27 +119,46 @@ set :chef_upload_location, "/tmp/toquen"
99
119
  ## View Instances
100
120
  To see details about your aws instances you can use the **details** cap task.
101
121
 
102
- $ cap all details
122
+ ```shell
123
+ cap all details
124
+ ```
103
125
 
104
126
  Or for a given role with:
105
127
 
106
- $ cap <role name> details
128
+ ```shell
129
+ cap <role name> details
130
+ ```
107
131
 
108
132
  Or for a given server with:
109
133
 
110
- $ cap server-<server name> details
134
+ ```shell
135
+ cap server-<server name> details
136
+ ```
111
137
 
112
138
  ## Open SSH to Current Machine
113
139
  To allow an SSH connection from your current machine (based on your internet visible IP, as determined using [this method](http://findingscience.com/internet/ruby/2014/05/17/stunning:-determining-your-public-ip.html)), use the open_ssh/close_ssh capistrano tasks.
114
140
 
115
- $ cap databases open_ssh
141
+ ```shell
142
+ cap databases open_ssh
143
+ ```
116
144
 
117
145
  And then, when you're finished:
118
146
 
119
- $ cap databases close_ssh
147
+ ```shell
148
+ cap databases close_ssh
149
+ ```
120
150
 
121
151
  Or, if you want to do everything in one step:
122
152
 
123
- $ cap databases open_ssh cook close_ssh
153
+ ```shell
154
+ cap databases open_ssh cook close_ssh
155
+ ```
156
+
157
+ **Note**: You can also use the task *open_port[22]* and *close_port[22]* to open and close SSH (or any other port).
158
+
159
+ ## Additional Cap Tasks
160
+ There are a few other helper cap tasks as well - to see them, run:
124
161
 
125
- **Note**: You can also use the task *open_port[22]* and *close_port[22]* to open and close SSH (or any other port).
162
+ ```shell
163
+ cap -T
164
+ ```
data/lib/toquen.rb CHANGED
@@ -8,10 +8,11 @@ require "toquen/details_table"
8
8
 
9
9
  module Toquen
10
10
  class Config
11
- attr_accessor :aws_roles_extractor
11
+ attr_accessor :aws_roles_extractor, :aws_roles_setter
12
12
 
13
13
  def initialize
14
14
  @aws_roles_extractor = lambda { |inst| (inst.tags["Roles"] || "").split }
15
+ @aws_roles_setter = lambda { |ec2, inst, roles| ec2.tags.create(inst, 'Roles', :value => roles.sort.join(' ')) }
15
16
  end
16
17
  end
17
18
 
data/lib/toquen/aws.rb CHANGED
@@ -21,6 +21,38 @@ module Toquen
21
21
  }
22
22
  end
23
23
 
24
+ def add_role(ivips, role)
25
+ @regions.each do |region|
26
+ AWS.config(:access_key_id => @key_id, :secret_access_key => @key, :region => region)
27
+ ec2 = AWS::EC2.new
28
+ ec2.instances.map do |i|
29
+ if ivips.include? i.public_ip_address
30
+ roles = Toquen.config.aws_roles_extractor.call(i)
31
+ unless roles.include? role
32
+ roles << role
33
+ ec2.tags.create(i, 'Roles', :value => roles.uniq.sort.join(' '))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def remove_role(ivips, role)
41
+ @regions.each do |region|
42
+ AWS.config(:access_key_id => @key_id, :secret_access_key => @key, :region => region)
43
+ ec2 = AWS::EC2.new
44
+ ec2.instances.map do |i|
45
+ if ivips.include? i.public_ip_address
46
+ roles = Toquen.config.aws_roles_extractor.call(i)
47
+ if roles.include? role
48
+ roles = roles.reject { |r| r == role }
49
+ Toquen.config.aws_roles_setter.call(ec2, i, roles.uniq)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
24
56
  def get_security_groups(ids)
25
57
  ectwo = AWS::EC2.new
26
58
  ids.map { |id| ectwo.security_groups[id] }
@@ -86,6 +86,30 @@ task :cook do
86
86
  end
87
87
  before :cook, :update_kitchen
88
88
 
89
+ desc "Add given role to machines"
90
+ task :add_role, :role do |t, args|
91
+ run_locally do
92
+ if args[:role].nil? or args[:role].empty?
93
+ error "You must give the role to add"
94
+ else
95
+ aws = Toquen::AWSProxy.new
96
+ aws.add_role roles(:all), args[:role]
97
+ end
98
+ end
99
+ end
100
+
101
+ desc "Remove given role from machines"
102
+ task :remove_role, :role do |t, args|
103
+ run_locally do
104
+ if args[:role].nil? or args[:role].empty?
105
+ error "You must give the role to remove"
106
+ else
107
+ aws = Toquen::AWSProxy.new
108
+ aws.remove_role roles(:all), args[:role]
109
+ end
110
+ end
111
+ end
112
+
89
113
  desc "Open a port of ingress to the current machine"
90
114
  task :open_port, :port do |t, args|
91
115
  port = (args[:port] || 22).to_i
@@ -1,3 +1,3 @@
1
1
  module Toquen
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
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.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Muller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano