fhcap-cli 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rakeTasks +7 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +150 -0
- data/Rakefile +2 -0
- data/bin/fhcap +6 -0
- data/fhcap-cli.gemspec +44 -0
- data/lib/cookbooks/provision/libraries/provision.rb +140 -0
- data/lib/cookbooks/provision/metadata.rb +7 -0
- data/lib/cookbooks/provision/recipes/aws.rb +15 -0
- data/lib/cookbooks/provision/recipes/aws_cluster_create.rb +59 -0
- data/lib/cookbooks/provision/recipes/aws_cluster_create_elb.rb +61 -0
- data/lib/cookbooks/provision/recipes/aws_cluster_destroy.rb +52 -0
- data/lib/cookbooks/provision/recipes/cluster_create.rb +2 -0
- data/lib/cookbooks/provision/recipes/cluster_destroy.rb +2 -0
- data/lib/cookbooks/provision/recipes/cluster_destroy_instances.rb +11 -0
- data/lib/cookbooks/provision/recipes/cluster_provision.rb +4 -0
- data/lib/cookbooks/provision/recipes/cluster_provision_instances.rb +55 -0
- data/lib/cookbooks/provision/recipes/cluster_status.rb +24 -0
- data/lib/cookbooks/provision/recipes/common.rb +9 -0
- data/lib/cookbooks/provision/recipes/default.rb +5 -0
- data/lib/cookbooks/provision/recipes/openstack.rb +11 -0
- data/lib/cookbooks/provision/recipes/openstack_cluster_create.rb +11 -0
- data/lib/cookbooks/provision/recipes/openstack_cluster_destroy.rb +4 -0
- data/lib/cookbooks/provision/recipes/reset_rabbitmq.rb +49 -0
- data/lib/cookbooks/provision/recipes/restart_services.rb +24 -0
- data/lib/extensions/chef/provisioning.rb +21 -0
- data/lib/extensions/chef/provisioning/aws_driver/driver.rb +46 -0
- data/lib/extensions/chef/provisioning/chef_run_data.rb +18 -0
- data/lib/extensions/cheffish/merged_config.rb +9 -0
- data/lib/fhcap.rb +14 -0
- data/lib/fhcap/chef-dk/chef_runner.rb +94 -0
- data/lib/fhcap/cli.rb +75 -0
- data/lib/fhcap/cluster.rb +112 -0
- data/lib/fhcap/config.rb +104 -0
- data/lib/fhcap/cookbook.rb +75 -0
- data/lib/fhcap/dummy_node.rb +80 -0
- data/lib/fhcap/fhcap_helper.rb +9 -0
- data/lib/fhcap/kitchen.rb +235 -0
- data/lib/fhcap/knife.rb +74 -0
- data/lib/fhcap/knife_helper.rb +38 -0
- data/lib/fhcap/misc.rb +103 -0
- data/lib/fhcap/provider.rb +41 -0
- data/lib/fhcap/providers_helper.rb +60 -0
- data/lib/fhcap/repo.rb +52 -0
- data/lib/fhcap/repos_helper.rb +217 -0
- data/lib/fhcap/tasks/chef/chef_task_base.rb +82 -0
- data/lib/fhcap/tasks/chef/cookbook/list.rb +37 -0
- data/lib/fhcap/tasks/chef/cookbook/update_changelog.rb +63 -0
- data/lib/fhcap/tasks/chef/cookbook/update_metadata.rb +57 -0
- data/lib/fhcap/tasks/chef/cookbook/update_readme.rb +30 -0
- data/lib/fhcap/tasks/chef/cookbook/update_version.rb +90 -0
- data/lib/fhcap/tasks/chef/environments/create.rb +115 -0
- data/lib/fhcap/tasks/chef/environments/destroy.rb +37 -0
- data/lib/fhcap/tasks/chef/environments/promote_cookbooks.rb +47 -0
- data/lib/fhcap/tasks/chef/provisioning/chef_provisioning_task.rb +27 -0
- data/lib/fhcap/tasks/chef/provisioning/chef_provisioning_task_base.rb +38 -0
- data/lib/fhcap/tasks/chef/provisioning/create.rb +22 -0
- data/lib/fhcap/tasks/chef/provisioning/destroy.rb +21 -0
- data/lib/fhcap/tasks/chef/provisioning/provision.rb +19 -0
- data/lib/fhcap/tasks/chef/server/bootstrap.rb +165 -0
- data/lib/fhcap/tasks/chef/server/create_user.rb +97 -0
- data/lib/fhcap/tasks/chef/server/info.rb +82 -0
- data/lib/fhcap/tasks/chef/server/provision.rb +45 -0
- data/lib/fhcap/tasks/clean.rb +34 -0
- data/lib/fhcap/tasks/cluster/cluster_task_base.rb +57 -0
- data/lib/fhcap/tasks/cluster/create.rb +243 -0
- data/lib/fhcap/tasks/cluster/create_environment.rb +171 -0
- data/lib/fhcap/tasks/cluster/destroy.rb +30 -0
- data/lib/fhcap/tasks/cluster/destroy_environment.rb +28 -0
- data/lib/fhcap/tasks/cluster/info.rb +67 -0
- data/lib/fhcap/tasks/cluster/list.rb +40 -0
- data/lib/fhcap/tasks/cluster/provision.rb +46 -0
- data/lib/fhcap/tasks/cluster/status.rb +17 -0
- data/lib/fhcap/tasks/cluster/test.rb +15 -0
- data/lib/fhcap/tasks/knife/add.rb +111 -0
- data/lib/fhcap/tasks/knife/list.rb +22 -0
- data/lib/fhcap/tasks/knife/remove.rb +39 -0
- data/lib/fhcap/tasks/misc/create_dns_record.rb +100 -0
- data/lib/fhcap/tasks/misc/create_ssl_cert.rb +82 -0
- data/lib/fhcap/tasks/provider/add.rb +136 -0
- data/lib/fhcap/tasks/provider/list.rb +31 -0
- data/lib/fhcap/tasks/provider/remove.rb +28 -0
- data/lib/fhcap/tasks/repo/add.rb +57 -0
- data/lib/fhcap/tasks/repo/checkout.rb +144 -0
- data/lib/fhcap/tasks/repo/list.rb +22 -0
- data/lib/fhcap/tasks/repo/remove.rb +34 -0
- data/lib/fhcap/tasks/setup.rb +59 -0
- data/lib/fhcap/tasks/task_base.rb +89 -0
- data/lib/fhcap/thor_base.rb +121 -0
- data/lib/fhcap/version.rb +3 -0
- data/spec/fhcap/cli_spec.rb +6 -0
- data/spec/fhcap/tasks/cluster/create_spec.rb +46 -0
- data/spec/fhcap/tasks/knife/add_spec.rb +35 -0
- data/spec/fhcap/tasks/knife/remove_spec.rb +25 -0
- data/spec/fhcap/tasks/provider/add_spec.rb +61 -0
- data/spec/fhcap/tasks/provider/remove_spec.rb +25 -0
- data/spec/fhcap/tasks/repo/add_spec.rb +32 -0
- data/spec/fhcap/tasks/repo/remove_spec.rb +25 -0
- data/spec/fhcap/tasks/task_base_spec.rb +51 -0
- data/spec/fhcap/thor_base_spec.rb +9 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/dummy_config.rb +7 -0
- data/spec/support/dummy_thor.rb +3 -0
- data/templates/chef/cookbook/changelog.md.erb +12 -0
- data/templates/chef/cookbook/metadata.erb +45 -0
- data/templates/chef/environment_core.json.erb +278 -0
- data/templates/chef/environment_empty.json.erb +10 -0
- data/templates/chef/environment_mbaas.json.erb +120 -0
- data/templates/chef/environment_single.json.erb +300 -0
- data/templates/cluster/aws/common.json.erb +43 -0
- data/templates/cluster/aws/core-3node.json.erb +106 -0
- data/templates/cluster/aws/core-small-9node.json.erb +333 -0
- data/templates/cluster/aws/mbaas-3node.json.erb +116 -0
- data/templates/cluster/aws/nginx-test.json.erb +93 -0
- data/templates/cluster/aws/single-blank.json.erb +41 -0
- data/templates/cluster/aws/single.json.erb +88 -0
- data/templates/cluster/core-3node.json.erb +8 -0
- data/templates/cluster/core-mbaas-6node.json.erb +13 -0
- data/templates/cluster/core-small-9node.json.erb +8 -0
- data/templates/cluster/mbaas-3node.json.erb +9 -0
- data/templates/cluster/nginx-test.json.erb +8 -0
- data/templates/cluster/openstack/common.json.erb +7 -0
- data/templates/cluster/openstack/core-3node.json.erb +14 -0
- data/templates/cluster/openstack/core-small-9node.json.erb +32 -0
- data/templates/cluster/openstack/mbaas-3node.json.erb +14 -0
- data/templates/cluster/openstack/nginx-test.json.erb +11 -0
- data/templates/cluster/openstack/single-blank.json.erb +10 -0
- data/templates/cluster/openstack/single.json.erb +10 -0
- data/templates/cluster/single-blank.json.erb +8 -0
- data/templates/cluster/single.json.erb +8 -0
- data/templates/init/knife.rb.erb +13 -0
- data/templates/kitchen/Cheffile.erb +11 -0
- data/templates/kitchen/kitchen.aws.yml.erb +35 -0
- data/templates/kitchen/kitchen.docker.yml.erb +24 -0
- data/templates/kitchen/kitchen.generate.yml.erb +2 -0
- data/templates/kitchen/kitchen.openstack.yml.erb +31 -0
- metadata +506 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::aws"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
|
7
|
+
key_pair_name = key_pair_name_for(org_name)
|
8
|
+
aws_key_pair key_pair_name
|
9
|
+
|
10
|
+
#aws_key_pair 'my-aws-key' do
|
11
|
+
# private_key_path "~boiardi/.ssh/my-aws-key.pem"
|
12
|
+
# public_key_path "~boiardi/.ssh/my-aws-key.pub"
|
13
|
+
# allow_overwrite false # Set to true if you want to regenerate this each chef run
|
14
|
+
#end
|
15
|
+
|
16
|
+
#Create VPC
|
17
|
+
vpc_name = vpc_name_for(org_name)
|
18
|
+
|
19
|
+
aws_vpc vpc_name do
|
20
|
+
cidr_block cluster_config[:vpc][:cidr]
|
21
|
+
internet_gateway true
|
22
|
+
main_routes '0.0.0.0/0' => :internet_gateway
|
23
|
+
end
|
24
|
+
|
25
|
+
# Create Security Groups
|
26
|
+
cluster_config[:security_groups].each do |sg_name, sg_config|
|
27
|
+
aws_security_group security_group_name_for(org_name, sg_name) do
|
28
|
+
vpc vpc_name
|
29
|
+
inbound_rules inbound_rules_for(org_name, sg_config[:authorize_ingress])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create Route Tables
|
34
|
+
cluster_config[:environments].each do |env, env_config|
|
35
|
+
|
36
|
+
env_route_table = route_table_name_for(org_name, env)
|
37
|
+
aws_route_table env_route_table do
|
38
|
+
vpc vpc_name
|
39
|
+
routes '0.0.0.0/0' => :internet_gateway
|
40
|
+
end
|
41
|
+
|
42
|
+
env_config[:subnets].each do |subnet_suffix, subnet_config|
|
43
|
+
|
44
|
+
subnet_name = subnet_name_for(org_name, env, subnet_suffix)
|
45
|
+
aws_subnet subnet_name do
|
46
|
+
vpc vpc_name
|
47
|
+
cidr_block subnet_config[:cidr]
|
48
|
+
availability_zone subnet_config[:availability_zone]
|
49
|
+
route_table env_route_table
|
50
|
+
map_public_ip_on_launch true
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
include_recipe "provision::cluster_provision_instances"
|
58
|
+
|
59
|
+
include_recipe "provision::aws_cluster_create_elb"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::aws"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
|
7
|
+
# Create Load Balancers
|
8
|
+
cluster_config[:environments].each do |env, env_config|
|
9
|
+
|
10
|
+
env_config[:load_balancers].each do |lb_name, lb_config|
|
11
|
+
|
12
|
+
lb_config[:security_groups] = lb_config[:security_groups].collect do |security_group|
|
13
|
+
security_group_name_for(org_name, security_group)
|
14
|
+
end
|
15
|
+
|
16
|
+
lb_config[:subnets] = lb_config[:subnets].collect do |subnet_name|
|
17
|
+
subnet_name_for(org_name, env, subnet_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
lb_certs = {}
|
21
|
+
lb_config[:listeners].each_with_index do |listener, index|
|
22
|
+
if listener[:server_certificate]
|
23
|
+
certificate_file = File.join(node[:local_repo_path], 'clusters', 'ssl_certs', "#{listener[:server_certificate]}-certificate.pem")
|
24
|
+
private_key_file = File.join(node[:local_repo_path], 'clusters', 'ssl_certs', "#{listener[:server_certificate]}-private-key.pem")
|
25
|
+
|
26
|
+
if File.exists?(certificate_file) && File.exists?(private_key_file)
|
27
|
+
certificate_body = File.open(certificate_file, "rb").read
|
28
|
+
private_key = File.open(private_key_file, "rb").read
|
29
|
+
|
30
|
+
cert_name = listener[:server_certificate]
|
31
|
+
lb_certs[index] = aws_server_certificate cert_name do
|
32
|
+
certificate_body certificate_body
|
33
|
+
private_key private_key
|
34
|
+
end
|
35
|
+
else
|
36
|
+
Chef::Log.warn("Could not find #{listener[:server_certificate]} locally to upload. Is this certificate already registered? ELB create will fail if it does not exist!!")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
lb_machines = env_config[:instances].select do |instance_name, instance_config|
|
42
|
+
instance_config[:load_balancers] && instance_config[:load_balancers].include?(lb_name.to_s)
|
43
|
+
end.collect do |instance_name, instance_config|
|
44
|
+
instance_name_for(org_name, env, instance_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
lb_name = load_balancer_name_for(org_name, env, lb_name)
|
48
|
+
load_balancer lb_name do
|
49
|
+
machines lb_machines
|
50
|
+
load_balancer_options(
|
51
|
+
lazy do
|
52
|
+
lb_certs.each do |index, cert|
|
53
|
+
lb_config[:listeners][index][:server_certificate] = cert.aws_object.arn
|
54
|
+
end
|
55
|
+
lb_config
|
56
|
+
end
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
end if env_config[:load_balancers]
|
61
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::aws"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
|
6
|
+
org_name = cluster_config[:id]
|
7
|
+
|
8
|
+
node_names = node_names_for(cluster_config)
|
9
|
+
|
10
|
+
machine_batch do
|
11
|
+
machines node_names
|
12
|
+
action :destroy
|
13
|
+
end
|
14
|
+
|
15
|
+
# Clear all rules from Security Groups
|
16
|
+
cluster_config[:security_groups].each do |sg_name, sg_config|
|
17
|
+
aws_security_group security_group_name_for(org_name, sg_name) do
|
18
|
+
inbound_rules []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
vpc_name = vpc_name_for(org_name)
|
23
|
+
aws_vpc vpc_name do
|
24
|
+
action :purge
|
25
|
+
end
|
26
|
+
|
27
|
+
cluster_config[:environments].each do |env, env_config|
|
28
|
+
|
29
|
+
aws_route_table route_table_name_for(org_name, env) do
|
30
|
+
action :destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
env_config[:subnets].each do |subnet_suffix, subnet_config|
|
34
|
+
aws_subnet subnet_name_for(org_name, env, subnet_suffix) do
|
35
|
+
action :destroy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
cluster_config[:environments].each do |env, env_config|
|
42
|
+
env_config[:load_balancers].each do |lb_name, lb_config|
|
43
|
+
lb_name = load_balancer_name_for(org_name, env, lb_name)
|
44
|
+
load_balancer lb_name do
|
45
|
+
action :destroy
|
46
|
+
end
|
47
|
+
end if env_config[:load_balancers]
|
48
|
+
end
|
49
|
+
|
50
|
+
aws_key_pair key_pair_name_for(org_name) do
|
51
|
+
action :destroy
|
52
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
include_recipe "provision::common"
|
2
|
+
include_recipe "provision::#{node['driver']}"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
node_names = node_names_for(cluster_config)
|
7
|
+
|
8
|
+
machine_batch do
|
9
|
+
machines node_names
|
10
|
+
action :destroy
|
11
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
cluster_config = cluster_config_for(node)
|
2
|
+
org_name = cluster_config[:id]
|
3
|
+
|
4
|
+
# Create/Provision Instances
|
5
|
+
default_instance_options = cluster_config[:default_instance_options]
|
6
|
+
cluster_config[:environments].each do |env, env_config|
|
7
|
+
chef_environment = fh_name_for(org_name, env)
|
8
|
+
|
9
|
+
instances = {}
|
10
|
+
env_config[:instances].each do |instance_name, instance_config|
|
11
|
+
instances[instance_name_for(org_name, env, instance_name)] = {}
|
12
|
+
instances[instance_name_for(org_name, env, instance_name)][:instance_config] = instance_config
|
13
|
+
instances[instance_name_for(org_name, env, instance_name)][:machine_options] = machine_options_for(cluster_config[:driver], org_name, env, default_instance_options.merge(instance_config[cluster_config[:driver].to_sym] || {}))
|
14
|
+
end
|
15
|
+
|
16
|
+
current_nodes = search(:node, "chef_environment:#{chef_environment}").map { |n| n.name }
|
17
|
+
required_nodes = instances.keys
|
18
|
+
missing_nodes = required_nodes - current_nodes
|
19
|
+
|
20
|
+
with_chef_environment chef_environment do
|
21
|
+
|
22
|
+
machine_batch do
|
23
|
+
missing_nodes.each do |instance_name|
|
24
|
+
machine_options = instances[instance_name][:machine_options]
|
25
|
+
machine instance_name do
|
26
|
+
chef_environment chef_environment
|
27
|
+
run_list ["recipe[feedhenry_common::hostname]"]
|
28
|
+
machine_options(machine_options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
not_if { missing_nodes.empty? }
|
32
|
+
end
|
33
|
+
|
34
|
+
if required_nodes.length > 1
|
35
|
+
converge_times = missing_nodes.empty? ? 1 : 3
|
36
|
+
else
|
37
|
+
converge_times = 1
|
38
|
+
end
|
39
|
+
|
40
|
+
converge_times.times do
|
41
|
+
machine_batch do
|
42
|
+
required_nodes.each do |instance_name|
|
43
|
+
machine_options = instances[instance_name][:machine_options]
|
44
|
+
instance_config = instances[instance_name][:instance_config]
|
45
|
+
machine instance_name do
|
46
|
+
chef_environment chef_environment
|
47
|
+
run_list instance_config[:run_list]
|
48
|
+
machine_options(machine_options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::#{node['driver']}"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
|
7
|
+
cluster_config[:environments].each do |env, env_config|
|
8
|
+
chef_environment = fh_name_for(org_name, env)
|
9
|
+
|
10
|
+
nodes = search(:node, "chef_environment:#{chef_environment}")
|
11
|
+
|
12
|
+
with_chef_environment chef_environment do
|
13
|
+
|
14
|
+
nodes.each do |n|
|
15
|
+
machine_execute 'sudo fhctl status' do
|
16
|
+
live_stream true
|
17
|
+
machine n.name
|
18
|
+
only_if {n.recipes.include? 'feedhenry_common::fhctl'}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
raise "Missing cluster id" unless node['id']
|
3
|
+
raise "Missing driver" unless node['driver']
|
4
|
+
raise "Missing chef server config" unless node['chef_server_config']
|
5
|
+
|
6
|
+
with_chef_server node['chef_server_config']['chef_server_url'],
|
7
|
+
:client_name => node['chef_server_config']['node_name'],
|
8
|
+
:signing_key_filename => node['chef_server_config']['client_key'],
|
9
|
+
:ssl_verify_mode => :verify_none
|
@@ -0,0 +1,11 @@
|
|
1
|
+
raise "Missing openstack credentials" unless node['provider_credentials']['os-username'] && node['provider_credentials']['os-password']
|
2
|
+
|
3
|
+
require 'chef/provisioning/fog_driver/driver'
|
4
|
+
|
5
|
+
os_auth_url = File.join(node['provider_credentials']['os-auth-url'], 'tokens')
|
6
|
+
with_driver "fog:OpenStack:#{os_auth_url}", :compute_options => {
|
7
|
+
:openstack_username => node['provider_credentials']['os-username'],
|
8
|
+
:openstack_api_key => node['provider_credentials']['os-password'],
|
9
|
+
:openstack_auth_url => os_auth_url,
|
10
|
+
:openstack_tenant => node['provider_credentials']['os-tenant-name']
|
11
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
include_recipe 'provision::common'
|
3
|
+
include_recipe "provision::openstack"
|
4
|
+
|
5
|
+
cluster_config = cluster_config_for(node)
|
6
|
+
org_name = cluster_config[:id]
|
7
|
+
|
8
|
+
key_pair_name = key_pair_name_for(org_name)
|
9
|
+
fog_key_pair key_pair_name
|
10
|
+
|
11
|
+
include_recipe "provision::cluster_provision_instances"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::#{node['driver']}"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
|
7
|
+
default_instance_options = cluster_config[:default_instance_options]
|
8
|
+
cluster_config[:environments].each do |env, env_config|
|
9
|
+
chef_environment = fh_name_for(org_name, env)
|
10
|
+
|
11
|
+
instances = {}
|
12
|
+
env_config[:instances].each do |instance_name, instance_config|
|
13
|
+
instances[instance_name_for(org_name, env, instance_name)] = {}
|
14
|
+
instances[instance_name_for(org_name, env, instance_name)][:instance_config] = instance_config
|
15
|
+
instances[instance_name_for(org_name, env, instance_name)][:machine_options] = machine_options_for(cluster_config[:driver], org_name, env, default_instance_options.merge(instance_config[cluster_config[:driver].to_sym] || {}))
|
16
|
+
end
|
17
|
+
|
18
|
+
rabbit_nodes = search(:node, "chef_environment:#{chef_environment} AND roles:rabbitmq_server").map { |n| n.name }
|
19
|
+
|
20
|
+
with_chef_environment chef_environment do
|
21
|
+
|
22
|
+
rabbit_nodes.each do |instance_name|
|
23
|
+
machine_execute 'sudo rabbitmqctl stop_app' do
|
24
|
+
machine instance_name
|
25
|
+
end
|
26
|
+
|
27
|
+
machine_execute 'sudo rabbitmqctl reset' do
|
28
|
+
machine instance_name
|
29
|
+
end
|
30
|
+
|
31
|
+
machine_execute 'sudo rabbitmqctl start_app' do
|
32
|
+
machine instance_name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
machine_batch do
|
37
|
+
rabbit_nodes.each do |instance_name|
|
38
|
+
machine_options = instances[instance_name][:machine_options]
|
39
|
+
instance_config = instances[instance_name][:instance_config]
|
40
|
+
machine instance_name do
|
41
|
+
chef_environment chef_environment
|
42
|
+
run_list instance_config[:run_list]
|
43
|
+
machine_options(machine_options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
include_recipe 'provision::common'
|
2
|
+
include_recipe "provision::#{node['driver']}"
|
3
|
+
|
4
|
+
cluster_config = cluster_config_for(node)
|
5
|
+
org_name = cluster_config[:id]
|
6
|
+
|
7
|
+
cluster_config[:environments].each do |env, env_config|
|
8
|
+
chef_environment = fh_name_for(org_name, env)
|
9
|
+
|
10
|
+
nodes = search(:node, "chef_environment:#{chef_environment}")
|
11
|
+
|
12
|
+
with_chef_environment chef_environment do
|
13
|
+
|
14
|
+
nodes.each do |n|
|
15
|
+
machine_execute 'sudo fhctl restart' do
|
16
|
+
live_stream true
|
17
|
+
machine n.name
|
18
|
+
only_if {n.recipes.include? 'feedhenry_common::fhctl'}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Chef
|
2
|
+
module Provisioning
|
3
|
+
|
4
|
+
def self.connect_to_machine(machine_spec, config = Cheffish.profiled_config, driver=nil)
|
5
|
+
|
6
|
+
chef_server = Cheffish.default_chef_server(config)
|
7
|
+
if machine_spec.is_a?(String)
|
8
|
+
machine_spec = chef_managed_entry_store(chef_server).get(:machine, machine_spec)
|
9
|
+
end
|
10
|
+
driver = driver_for_url(machine_spec.driver_url, config) unless driver
|
11
|
+
if driver
|
12
|
+
machine_options = {:convergence_options => {:chef_server => chef_server}}
|
13
|
+
machine_options = Cheffish::MergedConfig.new(config[:machine_options], machine_options) if config[:machine_options]
|
14
|
+
driver.connect_to_machine(machine_spec, machine_options)
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Chef
|
2
|
+
module Provisioning
|
3
|
+
module AWSDriver
|
4
|
+
class Driver < Chef::Provisioning::Driver
|
5
|
+
|
6
|
+
def initialize(driver_url, config)
|
7
|
+
super
|
8
|
+
|
9
|
+
_, profile_name, region = driver_url.split(':')
|
10
|
+
profile_name = nil if profile_name && profile_name.empty?
|
11
|
+
region = nil if region && region.empty?
|
12
|
+
|
13
|
+
credentials = profile_name ? aws_credentials[profile_name] : aws_credentials.default
|
14
|
+
@aws_config = AWS.config(
|
15
|
+
access_key_id: credentials[:aws_access_key_id],
|
16
|
+
secret_access_key: credentials[:aws_secret_access_key],
|
17
|
+
region: region || credentials[:region],
|
18
|
+
proxy_uri: credentials[:proxy_uri] || nil,
|
19
|
+
session_token: credentials[:aws_session_token] || nil,
|
20
|
+
logger: Chef::Log.logger
|
21
|
+
)
|
22
|
+
|
23
|
+
# TODO document how users could add something to the Aws.config themselves if they want to
|
24
|
+
# Right now we are supporting both V1 and V2, so we create 2 config sets
|
25
|
+
credentials2 = ::Aws::Credentials.new(
|
26
|
+
credentials[:aws_access_key_id],
|
27
|
+
credentials[:aws_secret_access_key],
|
28
|
+
ENV["AWS_SESSION_TOKEN"]
|
29
|
+
)
|
30
|
+
|
31
|
+
Chef::Config.chef_provisioning ||= {}
|
32
|
+
::Aws.config.update(
|
33
|
+
credentials: credentials2,
|
34
|
+
region: region || ENV["AWS_DEFAULT_REGION"] || credentials[:region],
|
35
|
+
# TODO when we get rid of V1 replace the credentials class with something that knows how
|
36
|
+
# to read ~/.aws/config
|
37
|
+
:http_proxy => credentials[:proxy_uri] || nil,
|
38
|
+
logger: Chef::Log.logger,
|
39
|
+
retry_limit: Chef::Config.chef_provisioning[:aws_retry_limit] || 5
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|