chef-sync 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/bin/chef-sync +38 -4
- data/lib/chef-sync/utils.rb +2 -2
- data/lib/chef-sync/version.rb +1 -1
- data/spec/fixtures/knife/node_search_ec2.json +5 -53
- metadata +8 -2
data/Gemfile.lock
CHANGED
data/bin/chef-sync
CHANGED
@@ -4,6 +4,17 @@ require 'optparse'
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'chef-sync'
|
6
6
|
|
7
|
+
CONFIG_PATH = '.chef-sync/config'
|
8
|
+
|
9
|
+
DEFAULT_ROLE_MAPPING = {
|
10
|
+
'rails_server' => [:app, :web],
|
11
|
+
'rails_utility' => :resque
|
12
|
+
}
|
13
|
+
|
14
|
+
DEFAULT_CONFIG = {
|
15
|
+
'roles' => DEFAULT_ROLE_MAPPING
|
16
|
+
}
|
17
|
+
|
7
18
|
options = {
|
8
19
|
:stages => true,
|
9
20
|
:mongo => true,
|
@@ -18,6 +29,7 @@ Capistrano multi-stage configuration, mongo server configuration, etc
|
|
18
29
|
EOL
|
19
30
|
|
20
31
|
opts.on('-t', '--target [DIR]', "Target Directory (defaults to current)") {|v| options[:target] = v }
|
32
|
+
opts.on('-i', '--init', "Initialize Default Config in target DIR") {|v| options[:init_config] = v }
|
21
33
|
opts.on('-s', '--[no-]stages', "Sync config/stages.yml") {|v| options[:stages] = v }
|
22
34
|
opts.on('-m', '--[no-]mongo', "Sync config/mongo.yml") {|v| options[:mongo] = v }
|
23
35
|
opts.on_tail("-h", "--help", "Show this message") do
|
@@ -43,10 +55,13 @@ end
|
|
43
55
|
def sync_stages(base_dir)
|
44
56
|
yaml_path = File.join(base_dir, 'config', 'stages.yml')
|
45
57
|
transform_yaml(yaml_path) do |stages_hash|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
58
|
+
|
59
|
+
config_file = File.join(base_dir, CONFIG_PATH)
|
60
|
+
synchronized_roles = if File.exists?(config_file)
|
61
|
+
JSON.parse(File.read(config_file))['roles']
|
62
|
+
else
|
63
|
+
DEFAULT_ROLE_MAPPING
|
64
|
+
end
|
50
65
|
|
51
66
|
puts "----------------------------------------------------------"
|
52
67
|
puts "- Synchronizing Cap config/stages.yml w/ Chef Node Set"
|
@@ -69,8 +84,27 @@ def sync_mongo(base_dir)
|
|
69
84
|
end
|
70
85
|
end
|
71
86
|
|
87
|
+
def generate_default_config(base_dir)
|
88
|
+
config_file = File.join(base_dir, CONFIG_PATH)
|
89
|
+
if File.exists?(config_file)
|
90
|
+
puts "WARNING: #{config_file} exists."
|
91
|
+
puts "Continue? (CTRL+C to quit)"
|
92
|
+
gets
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "----------------------------------------------------------"
|
96
|
+
puts "- Generating default config #{config_file}"
|
97
|
+
puts "----------------------------------------------------------"
|
98
|
+
%x{ mkdir -p #{File.dirname(config_file)} }
|
99
|
+
File.open(config_file, 'w') {|f| f.write( JSON.generate(DEFAULT_CONFIG) ) }
|
100
|
+
end
|
101
|
+
|
72
102
|
puts 'Target: '+options[:target]
|
73
103
|
|
104
|
+
if options[:init_config]
|
105
|
+
generate_default_config(options[:target])
|
106
|
+
exit
|
107
|
+
end
|
74
108
|
|
75
109
|
sync_stages(options[:target]) if options[:stages]
|
76
110
|
sync_mongo(options[:target]) if options[:mongo]
|
data/lib/chef-sync/utils.rb
CHANGED
@@ -7,7 +7,7 @@ module Chef::Sync::Utils
|
|
7
7
|
|
8
8
|
def self.public_hostnames_by_role(role, environment)
|
9
9
|
results = JSON.parse(exec_knife_node_search(role, environment))
|
10
|
-
hostnames = Array(results['rows']).map {|node| node['ec2
|
10
|
+
hostnames = Array(results['rows']).map {|node| node['ec2.public_hostname'] }
|
11
11
|
hostnames.sort
|
12
12
|
end
|
13
13
|
|
@@ -38,7 +38,7 @@ module Chef::Sync::Utils
|
|
38
38
|
|
39
39
|
private
|
40
40
|
def self.exec_knife_node_search(role, environment)
|
41
|
-
`knife search node 'role:#{ role } AND chef_environment:#{ environment }' -a ec2 -Fj`
|
41
|
+
`knife search node 'role:#{ role } AND chef_environment:#{ environment }' -a ec2.public_hostname -Fj`
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.exec_knife_node_list(environment)
|
data/lib/chef-sync/version.rb
CHANGED
@@ -2,60 +2,12 @@
|
|
2
2
|
"results": 2,
|
3
3
|
"rows": [
|
4
4
|
{
|
5
|
-
"ec2":
|
6
|
-
|
7
|
-
"public_ipv4": "107.22.89.198",
|
8
|
-
"reservation_id": "r-020ac561",
|
9
|
-
"public_keys_0_openssh_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKUUG53xhavex/7g/mjlX8qnff6i+xtY+DiLzu1Z+OFu3SD6a3McGDt+vUp7RTTfnKLURMgHsxREomCMxAMrM6oksK+UU3sAD+8xOZRK2R+wQmcZg1aGPKZm6UteYxUSoyDK4RBw127FO63llrU/VBZZcsbxr3nZH3iIGvtL31M2KH4XC/p6YQ6urCIfARNuhAZKwMPtZCw0Y3fkCSzcViZ1LbMi2d1/kJYkVWY6bvV7IFkXAFhYyaFFlsD0ihk9jt/IOQUBLX0qzXSfQ72FvEqN7lGaw0B2c2C7+RBs1EE3ElgCT8ld+a0Sn+BWDwUaz7H7tN8+jRXPvmLtLSyUED katama-prod\n",
|
10
|
-
"local_ipv4": "10.242.67.15",
|
11
|
-
"local_hostname": "ip-10-242-67-15.ec2.internal",
|
12
|
-
"security_groups": [
|
13
|
-
"private_web"
|
14
|
-
],
|
15
|
-
"hostname": "ip-10-242-67-15.ec2.internal",
|
16
|
-
"ami_id": "ami-4fa37426",
|
17
|
-
"placement_availability_zone": "us-east-1b",
|
18
|
-
"public_hostname": "ec2-107-22-89-198.compute-1.amazonaws.com",
|
19
|
-
"block_device_mapping_ami": "sda1",
|
20
|
-
"ami_launch_index": "0",
|
21
|
-
"ami_manifest_path": "ubuntu-us-east-1/images/ubuntu-oneiric-11.10-amd64-server-20120108.manifest.xml",
|
22
|
-
"instance_id": "i-d1da9ab5",
|
23
|
-
"userdata": null,
|
24
|
-
"profile": "default-paravirtual",
|
25
|
-
"instance_type": "m1.large",
|
26
|
-
"block_device_mapping_root": "/dev/sda1",
|
27
|
-
"block_device_mapping_ephemeral1": "sdc",
|
28
|
-
"block_device_mapping_ephemeral0": "sdb"
|
29
|
-
},
|
30
|
-
"id": "resque103.dav"
|
5
|
+
"ec2.public_hostname": "ec2-107-22-89-198.compute-1.amazonaws.com",
|
6
|
+
"id": "imagetranscode103.dav"
|
31
7
|
},
|
32
8
|
{
|
33
|
-
"ec2":
|
34
|
-
|
35
|
-
"ami_id": "ami-4fa37426",
|
36
|
-
"local_ipv4": "10.46.214.63",
|
37
|
-
"local_hostname": "ip-10-46-214-63.ec2.internal",
|
38
|
-
"public_ipv4": "23.20.177.134",
|
39
|
-
"hostname": "ip-10-46-214-63.ec2.internal",
|
40
|
-
"userdata": null,
|
41
|
-
"security_groups": [
|
42
|
-
"private_web"
|
43
|
-
],
|
44
|
-
"reservation_id": "r-d0f53ab3",
|
45
|
-
"ami_launch_index": "0",
|
46
|
-
"kernel_id": "aki-825ea7eb",
|
47
|
-
"block_device_mapping_ephemeral1": "sdc",
|
48
|
-
"placement_availability_zone": "us-east-1a",
|
49
|
-
"block_device_mapping_ephemeral0": "sdb",
|
50
|
-
"public_hostname": "ec2-23-20-177-134.compute-1.amazonaws.com",
|
51
|
-
"instance_id": "i-6fce8e0b",
|
52
|
-
"instance_type": "m1.large",
|
53
|
-
"ami_manifest_path": "ubuntu-us-east-1/images/ubuntu-oneiric-11.10-amd64-server-20120108.manifest.xml",
|
54
|
-
"public_keys_0_openssh_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKUUG53xhavex/7g/mjlX8qnff6i+xtY+DiLzu1Z+OFu3SD6a3McGDt+vUp7RTTfnKLURMgHsxREomCMxAMrM6oksK+UU3sAD+8xOZRK2R+wQmcZg1aGPKZm6UteYxUSoyDK4RBw127FO63llrU/VBZZcsbxr3nZH3iIGvtL31M2KH4XC/p6YQ6urCIfARNuhAZKwMPtZCw0Y3fkCSzcViZ1LbMi2d1/kJYkVWY6bvV7IFkXAFhYyaFFlsD0ihk9jt/IOQUBLX0qzXSfQ72FvEqN7lGaw0B2c2C7+RBs1EE3ElgCT8ld+a0Sn+BWDwUaz7H7tN8+jRXPvmLtLSyUED katama-prod\n",
|
55
|
-
"block_device_mapping_root": "/dev/sda1",
|
56
|
-
"block_device_mapping_ami": "sda1"
|
57
|
-
},
|
58
|
-
"id": "resque102.dav"
|
9
|
+
"ec2.public_hostname": "ec2-23-20-177-134.compute-1.amazonaws.com",
|
10
|
+
"id": "qa-imagetranscode001.hud"
|
59
11
|
}
|
60
12
|
]
|
61
|
-
}
|
13
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -113,12 +113,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- - ! '>='
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 2457399180150779435
|
116
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
120
|
none: false
|
118
121
|
requirements:
|
119
122
|
- - ! '>='
|
120
123
|
- !ruby/object:Gem::Version
|
121
124
|
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 2457399180150779435
|
122
128
|
requirements: []
|
123
129
|
rubyforge_project:
|
124
130
|
rubygems_version: 1.8.23
|