chef-provisioner 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eee64aaf33ec7bcd860f1875df929e1c2e3f28fe
4
+ data.tar.gz: 9349f6ef25fb3838506d06681265e2000b826d66
5
+ SHA512:
6
+ metadata.gz: 25719036b4a56009e3180d6fb77df911d7e2105652b436f5593a917c49324642eba2bc297f88f037bc87112682d2f2864c2452dce1f0432de7d9536f59752fab
7
+ data.tar.gz: 249951b39e0753a4ebb03b24c03d8fdc4f7591816cb57095bf39600b3aced13b4657ee827141b00c32ae16fc82cf5a79dac831a0810bbe7707ae173dc87c43ac
@@ -0,0 +1,22 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+
4
+ require 'chef-provisioner/chef'
5
+
6
+ module ChefProvisioner
7
+ # Help render the bootstrap script
8
+ module Bootstrap
9
+ extend self
10
+ BOOTSTRAP_TEMPLATE = File.read(File.expand_path('../../chef-provisioner/templates/bootstrap.erb', __FILE__)).freeze
11
+
12
+ def generate(client_pem:'', chef_version: '12.4.1', environment: 'default', server: 'localhost', node_name: '', first_boot: {})
13
+ render(client_pem: client_pem, chef_version: chef_version, environment: environment, server: server, node_name: node_name, first_boot: first_boot)
14
+ end
15
+
16
+ private
17
+
18
+ def render(**kwargs)
19
+ ERB.new(BOOTSTRAP_TEMPLATE).result(OpenStruct.new(**kwargs).instance_eval { binding })
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ require 'yaml'
2
+ require 'json'
3
+ require 'fileutils'
4
+ require 'chef-api'
5
+
6
+ module ChefProvisioner
7
+ # Simple API to access chef server to manage clients and nodes
8
+ module Chef
9
+ extend self
10
+
11
+ def configure(**kwargs)
12
+ ChefAPI.configure do |config|
13
+ config.endpoint = kwargs[:endpoint]
14
+ config.client = kwargs[:client]
15
+ config.key = kwargs[:key_path]
16
+ end
17
+ end
18
+
19
+ def init_server(name, attributes:{}, run_list:[])
20
+ key = create_client(name)
21
+ create_node(name, attributes: attributes, run_list: run_list)
22
+ key
23
+ end
24
+
25
+ def create_client(name)
26
+ client = ChefAPI::Resource::Client.create(name: name)
27
+ client.private_key
28
+ rescue => e
29
+ puts "Failed to create client #{name}"
30
+ puts e.message
31
+ end
32
+
33
+ def create_node(name, attributes:{}, run_list:[])
34
+ node = ChefAPI::Resource::Node.create(name: name, run_list: run_list)
35
+ node.automatic = attributes['automatic'] || {}
36
+ node.default = attributes['default'] || {}
37
+ node.normal = attributes['normal'] || {}
38
+ node.override = attributes['override'] || {}
39
+ node.save
40
+ rescue => e
41
+ puts "Failed to create node #{name}"
42
+ puts e.message
43
+ end
44
+
45
+ def delete_client(name)
46
+ ChefAPI::Resource::Client.destroy(name)
47
+ rescue => e
48
+ puts "Failed to delete client #{name}"
49
+ puts e.message
50
+ end
51
+
52
+ def delete_node(name)
53
+ ChefAPI::Resource::Node.destroy(name)
54
+ rescue => e
55
+ puts "Failed to delete node #{name}"
56
+ puts e.message
57
+ end
58
+
59
+ def nuke(name)
60
+ delete_client(name)
61
+ delete_node(name)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+ # Verbose output, no errors allowed
3
+ set -x
4
+ set -e
5
+
6
+ # Install chef
7
+ curl -L https://www.opscode.com/chef/install.sh | sudo bash /dev/stdin -v <%= chef_version %>
8
+ rm -rf /etc/chef
9
+ mkdir -p /etc/chef
10
+
11
+ # Create the node and client writing the private key back here
12
+ cat > /etc/chef/client.pem <<EOF
13
+ <%= client_pem %>
14
+ EOF
15
+
16
+ # Create the initial client spec
17
+ cat > /etc/chef/client.rb <<EOF
18
+ log_level :info
19
+ log_location STDOUT
20
+ ssl_verify_mode :verify_peer
21
+ environment "<%= environment %>"
22
+ chef_server_url "<%= server %>"
23
+ node_name "<%= node_name %>"
24
+ EOF
25
+
26
+ # Create the initial chef attributes
27
+ cat > /etc/chef/first_boot.json << EOF
28
+ <%= JSON.pretty_generate(first_boot) %>
29
+ EOF
30
+
31
+ # Start the chef run
32
+ chef-client -c /etc/chef/client.rb -j /etc/chef/first_boot.json | tee -a /var/log/chef_bootstrap.log
@@ -0,0 +1,4 @@
1
+ # Namespace for our gem
2
+ module ChefProvisioner
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
+
3
+ require 'chef-provisioner/version'
4
+ require 'chef-provisioner/chef'
5
+ require 'chef-provisioner/bootstrap'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-provisioner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dale Hamel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chef-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 10.4.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 10.4.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
83
+ description: Provides a means of easily bootstrapping against a fake, chef-zero server
84
+ email: dale.hamel@srvthe.net
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/chef-provisioner.rb
90
+ - lib/chef-provisioner/bootstrap.rb
91
+ - lib/chef-provisioner/chef.rb
92
+ - lib/chef-provisioner/templates/bootstrap.erb
93
+ - lib/chef-provisioner/version.rb
94
+ homepage: http://rubygems.org/gems/chef-zero-bootstrap
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Bootstrap against a chef-zero server
118
+ test_files: []
119
+ has_rdoc: