capichef 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/capichef.rb +76 -0
- data/lib/capichef/environment.rb +38 -0
- data/lib/capichef/node.rb +28 -0
- data/lib/capichef/role.rb +69 -0
- data/lib/capichef/version.rb +3 -0
- data/lib/spec_helper.rb +11 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTJlZGEzOGViNDRmOTQwMDkzODdmYThiMTI2Nzg2YmIxNzVkY2FlZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODBkYmJkMjM0YWE2ODA1MGIzZmY3ZTZiMjk4OTgzYmNhNDcxMTI3NA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTcyNTIxYjQ3NGRkOTAxNjMwM2FkNTY4YWZmNTAzZTFiZDcyMTliY2RhMzg5
|
10
|
+
MTFiM2U4MWZiM2FlZjlmMGQ1NzVjMDdmYmQ0ZDU4YzcyY2VmMmQ1MjQ4ZmFk
|
11
|
+
ZTIzOGUwMWY0YjNiMDExNzM1MzcwZjJjMDYxYjY2MjgwM2JmYzU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2VjY2Q0Y2NmOTA1YzlhYTVhMzM2NTZmZmI2YzQ2NjI1ZWJjMWIzNzE2ODkx
|
14
|
+
ZTdhMDhmN2Y5YWIyMTMyMjBkNjhkOWMxMWM3OTJhZDU3M2U0NThlZDlkYmI1
|
15
|
+
ZTQxMTYxZDM1YmQzYmNhMjYwYmI0ODM3NjFiYTcwYjFkMjliYzM=
|
data/lib/capichef.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/command'
|
3
|
+
require 'chef/knife'
|
4
|
+
require 'capichef/role'
|
5
|
+
require 'capichef/environment'
|
6
|
+
|
7
|
+
module Capichef
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
knife = Chef::Knife.new
|
11
|
+
Chef::Config[:verbosity] = 1
|
12
|
+
knife.configure_chef
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.replace_attribute_placeholder(string, node)
|
16
|
+
string.gsub %r{\$CAPICHEF_NODE:(.+?)\$} do |full_match|
|
17
|
+
attribute = node.attributes
|
18
|
+
$1.split('.').each do |key|
|
19
|
+
if attribute.attribute?(key)
|
20
|
+
attribute = attribute[key]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attribute.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.load_into(configuration)
|
29
|
+
self.configure
|
30
|
+
|
31
|
+
configuration.load do
|
32
|
+
def _cset(name, *args, &block)
|
33
|
+
unless exists?(name)
|
34
|
+
set(name, *args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :chef do
|
39
|
+
desc "Run chef on all server defined."
|
40
|
+
task :provision do
|
41
|
+
run "#{try_sudo} chef-client"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Hook that
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
Capichef::Environment.load_into(configuration)
|
50
|
+
Capichef::Role.load_into(configuration)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
if Capistrano::Configuration.instance
|
56
|
+
Capichef.load_into(Capistrano::Configuration.instance)
|
57
|
+
end
|
58
|
+
|
59
|
+
module Capistrano
|
60
|
+
def Command.process(tree, sessions, options={})
|
61
|
+
cmd = Command.new(tree, sessions, options)
|
62
|
+
|
63
|
+
def cmd.replace_placeholders(command, channel)
|
64
|
+
if (channel[:server].options.has_key?(:node))
|
65
|
+
command = Capichef.replace_attribute_placeholder(command, channel[:server].options[:node])
|
66
|
+
end
|
67
|
+
|
68
|
+
roles = @tree.configuration && @tree.configuration.role_names_for_host(channel[:server])
|
69
|
+
command = command.gsub(/\$CAPISTRANO:HOST\$/, channel[:host])
|
70
|
+
command.gsub!(/\$CAPISTRANO:HOSTROLES\$/, roles.join(',')) if roles
|
71
|
+
command
|
72
|
+
end
|
73
|
+
|
74
|
+
cmd.process!
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'chef/environment'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
module Capichef
|
5
|
+
module Environment
|
6
|
+
@@environments = nil
|
7
|
+
|
8
|
+
def self.list
|
9
|
+
if (!@@environments)
|
10
|
+
@@environments = Chef::Environment.list.keys
|
11
|
+
end
|
12
|
+
|
13
|
+
return @@environments
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.has?(environment)
|
17
|
+
return self.list.include?(environment)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load_into(configuration)
|
21
|
+
@@configuration = configuration
|
22
|
+
|
23
|
+
configuration.load do
|
24
|
+
_cset :chef_environments, Capichef::Environment.list
|
25
|
+
_cset :chef_environment, "_default"
|
26
|
+
|
27
|
+
def prompt_chef_environnment(default = "_default", &block)
|
28
|
+
begin
|
29
|
+
set(:chef_environment) do
|
30
|
+
Capistrano::CLI.ui.ask("Chef environment (one of #{Capichef::Environment.list.join(', ')}) [#{default}] : ", &block)
|
31
|
+
end
|
32
|
+
set :chef_environment, default if chef_environment.to_s.empty?
|
33
|
+
end while !Capichef::Environment.has?(chef_environment)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'chef/knife'
|
3
|
+
require 'chef/search/query'
|
4
|
+
|
5
|
+
module Capichef
|
6
|
+
module Node
|
7
|
+
def self.get_attribute(node, attribute)
|
8
|
+
case attribute
|
9
|
+
when Proc
|
10
|
+
role name, attribute.call(node)
|
11
|
+
when Hash
|
12
|
+
iface, family = attribute.keys.first.to_s, attribute.values.first.to_s
|
13
|
+
addresses = node["network"]["interfaces"][iface]["addresses"]
|
14
|
+
role name, addresses.select{|address, data| data["family"] == family }.to_a.first.first
|
15
|
+
when Symbol, String
|
16
|
+
role name, node[attribute.to_s].to_s
|
17
|
+
else
|
18
|
+
raise ArgumentError, 'Attribute must be Proc, Hash, Symbol, String.'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.load_into(configuration)
|
23
|
+
configuration.load do
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'chef/knife'
|
3
|
+
require 'chef/search/query'
|
4
|
+
|
5
|
+
module Capichef
|
6
|
+
module Role
|
7
|
+
def self.node_list(role_name, environment="_default")
|
8
|
+
nodes = []
|
9
|
+
query = sprintf("chef_environment:%s AND roles:%s", environment, role_name)
|
10
|
+
|
11
|
+
Chef::Search::Query.new.search(:node, query) do |result|
|
12
|
+
nodes.push(result)
|
13
|
+
end
|
14
|
+
|
15
|
+
nodes
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load_into(configuration)
|
19
|
+
configuration.load do
|
20
|
+
|
21
|
+
def search(type, query)
|
22
|
+
nodes = []
|
23
|
+
Chef::Search::Query.new.search(type, query) do |result|
|
24
|
+
nodes.push(result)
|
25
|
+
end
|
26
|
+
|
27
|
+
nodes
|
28
|
+
end
|
29
|
+
|
30
|
+
def chef_role(name, chef_role_name, options = {})
|
31
|
+
options = {:attribute => :ipaddress, :options_mapping => {}}.merge(options)
|
32
|
+
attribute = options.delete(:attribute)
|
33
|
+
options_mapping = options.delete(:options_mapping)
|
34
|
+
|
35
|
+
Capichef::Role.node_list(chef_role_name, chef_environment).each do |n|
|
36
|
+
node_options = Hash.new
|
37
|
+
|
38
|
+
options_mapping.each do |option, value|
|
39
|
+
case value
|
40
|
+
when Proc
|
41
|
+
node_options[option] = value.call(n)
|
42
|
+
when Symbol, String
|
43
|
+
node_options[option] = n[value.to_s]
|
44
|
+
else
|
45
|
+
raise ArgumentError, 'Option mapping value must be Proc, Symbol, String.'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
options[:node] = n
|
50
|
+
|
51
|
+
case attribute
|
52
|
+
when Proc
|
53
|
+
role name, attribute.call(n), name, options.merge(node_options)
|
54
|
+
when Hash
|
55
|
+
iface, family = attribute.keys.first.to_s, attribute.values.first.to_s
|
56
|
+
addresses = n["network"]["interfaces"][iface]["addresses"]
|
57
|
+
role name, addresses.select{|address, data| data["family"] == family }.to_a.first.first, options.merge(node_options)
|
58
|
+
when Symbol, String
|
59
|
+
role name, n[attribute.to_s].to_s, name, options.merge(node_options)
|
60
|
+
else
|
61
|
+
raise ArgumentError, 'Attribute option must be Proc, Hash, Symbol, String.'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capichef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Wurtz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chef
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.0
|
41
|
+
description: Allows capistrano to use Chef data, roles and environments for deployment.
|
42
|
+
Provides basics tasks to upgrade server with chef
|
43
|
+
email:
|
44
|
+
- jwurtz@jolicode.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- lib/capichef/environment.rb
|
50
|
+
- lib/capichef/node.rb
|
51
|
+
- lib/capichef/role.rb
|
52
|
+
- lib/capichef/version.rb
|
53
|
+
- lib/capichef.rb
|
54
|
+
- lib/spec_helper.rb
|
55
|
+
homepage: https://github.com/jolicode/capichef
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project: capichef
|
75
|
+
rubygems_version: 2.0.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Capistrano extensions for Chef Server integration
|
79
|
+
test_files: []
|