runa-chef 0.8.0.1
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.
- data/LICENSE +201 -0
- data/README.rdoc +136 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/bin/knife +27 -0
- data/bin/shef +45 -0
- data/distro/README +2 -0
- data/distro/common/man/man1/chef-indexer.1 +42 -0
- data/distro/common/man/man1/chef-server.1 +108 -0
- data/distro/common/man/man8/chef-client.8 +61 -0
- data/distro/common/man/man8/chef-solo.8 +58 -0
- data/distro/common/man/man8/knife.8 +359 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/redhat/etc/init.d/chef-client +78 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +78 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/api_client.rb +269 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +214 -0
- data/lib/chef/application/knife.rb +138 -0
- data/lib/chef/application/server.rb +19 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +323 -0
- data/lib/chef/compile.rb +158 -0
- data/lib/chef/config.rb +195 -0
- data/lib/chef/cookbook.rb +198 -0
- data/lib/chef/cookbook/metadata.rb +487 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +273 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/data_bag.rb +216 -0
- data/lib/chef/data_bag_item.rb +227 -0
- data/lib/chef/exceptions.rb +39 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/knife.rb +300 -0
- data/lib/chef/knife/client_bulk_delete.rb +41 -0
- data/lib/chef/knife/client_create.rb +55 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +84 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +173 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/node_bulk_delete.rb +44 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +45 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +390 -0
- data/lib/chef/mixin/convert_to_class_name.rb +57 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +33 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +58 -0
- data/lib/chef/mixin/language.rb +107 -0
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
- data/lib/chef/mixin/template.rb +94 -0
- data/lib/chef/nanite.rb +100 -0
- data/lib/chef/node.rb +463 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +268 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +184 -0
- data/lib/chef/provider/deploy.rb +314 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/erl_call.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +195 -0
- data/lib/chef/provider/git.rb +203 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/dscl.rb +128 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +106 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mdadm.rb +88 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/easy_install.rb +106 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +125 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/package/zypper.rb +132 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +33 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +156 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +114 -0
- data/lib/chef/provider/subversion.rb +156 -0
- data/lib/chef/provider/template.rb +175 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +108 -0
- data/lib/chef/recipe.rb +105 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +359 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +39 -0
- data/lib/chef/resource/scm.rb +137 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +34 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +101 -0
- data/lib/chef/resource_collection.rb +212 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +298 -0
- data/lib/chef/role.rb +301 -0
- data/lib/chef/run_list.rb +164 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search/query.rb +71 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +185 -0
- data/lib/chef/tasks/chef_repo.rake +245 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- data/lib/chef/webui_user.rb +231 -0
- metadata +398 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
require 'chef/log'
|
|
21
|
+
require 'chef/provider'
|
|
22
|
+
require 'chef/mixin/command'
|
|
23
|
+
require 'fileutils'
|
|
24
|
+
|
|
25
|
+
class Chef
|
|
26
|
+
class Provider
|
|
27
|
+
class Subversion < Chef::Provider
|
|
28
|
+
|
|
29
|
+
include Chef::Mixin::Command
|
|
30
|
+
|
|
31
|
+
def load_current_resource
|
|
32
|
+
@current_resource = Chef::Resource::Subversion.new(@new_resource.name)
|
|
33
|
+
if current_revision = find_current_revision
|
|
34
|
+
@current_resource.revision current_revision
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def action_checkout
|
|
39
|
+
run_command(run_options(:command => checkout_command))
|
|
40
|
+
@new_resource.updated = true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def action_export
|
|
44
|
+
run_command(run_options(:command => export_command))
|
|
45
|
+
@new_resource.updated = true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def action_force_export
|
|
49
|
+
run_command(run_options(:command => export_command(:force => true)))
|
|
50
|
+
@new_resource.updated = true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def action_sync
|
|
54
|
+
if !::File.exist?(@new_resource.destination + "/.svn") || ::Dir.entries(@new_resource.destination) == ['.','..']
|
|
55
|
+
action_checkout
|
|
56
|
+
else
|
|
57
|
+
run_command(run_options(:command => sync_command))
|
|
58
|
+
end
|
|
59
|
+
@new_resource.updated = true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def sync_command
|
|
63
|
+
Chef::Log.info "Updating working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
|
|
64
|
+
scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def checkout_command
|
|
68
|
+
Chef::Log.info "checking out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
|
69
|
+
scm :checkout, @new_resource.svn_arguments, verbose, authentication,
|
|
70
|
+
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def export_command(opts={})
|
|
74
|
+
Chef::Log.info "exporting #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
|
75
|
+
args = opts[:force] ? ["--force"] : []
|
|
76
|
+
args << @new_resource.svn_arguments << verbose << authentication <<
|
|
77
|
+
"-r#{revision_int}" << @new_resource.repository << @new_resource.destination
|
|
78
|
+
scm :export, *args
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# If the specified revision isn't an integer ("HEAD" for example), look
|
|
82
|
+
# up the revision id by asking the server
|
|
83
|
+
# If the specified revision is an integer, trust it.
|
|
84
|
+
def revision_int
|
|
85
|
+
@revision_int ||= begin
|
|
86
|
+
if @new_resource.revision =~ /^\d+$/
|
|
87
|
+
@new_resource.revision
|
|
88
|
+
else
|
|
89
|
+
command = scm(:info, @new_resource.repository, authentication, "-r#{@new_resource.revision}")
|
|
90
|
+
status, svn_info, error_message = output_of_command(command, run_options)
|
|
91
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
|
92
|
+
extract_revision_info(svn_info)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
alias :revision_slug :revision_int
|
|
98
|
+
|
|
99
|
+
def find_current_revision
|
|
100
|
+
return nil unless ::File.exist?(@new_resource.destination)
|
|
101
|
+
command = scm(:info)
|
|
102
|
+
status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
|
|
103
|
+
|
|
104
|
+
unless [0,1].include?(status.exitstatus)
|
|
105
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
|
106
|
+
end
|
|
107
|
+
extract_revision_info(svn_info)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def run_options(run_opts={})
|
|
111
|
+
run_opts[:user] = @new_resource.user if @new_resource.user
|
|
112
|
+
run_opts[:group] = @new_resource.group if @new_resource.group
|
|
113
|
+
run_opts
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def cwd
|
|
119
|
+
@new_resource.destination
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def verbose
|
|
123
|
+
"-q"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def extract_revision_info(svn_info)
|
|
127
|
+
begin
|
|
128
|
+
repo_attrs = YAML.load(svn_info)
|
|
129
|
+
rescue ArgumentError
|
|
130
|
+
# YAML doesn't appreciate input like "svn: '/tmp/deploydir' is not a working copy\n"
|
|
131
|
+
return nil
|
|
132
|
+
end
|
|
133
|
+
raise "Could not parse `svn info` data: #{svn_info}" unless repo_attrs.kind_of?(Hash)
|
|
134
|
+
rev = (repo_attrs['Last Changed Rev'] || repo_attrs['Revision']).to_s
|
|
135
|
+
Chef::Log.debug "Resolved revision #{@new_resource.revision} to #{rev}"
|
|
136
|
+
rev
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# If a username is configured for the SCM, return the command-line
|
|
140
|
+
# switches for that. Note that we don't need to return the password
|
|
141
|
+
# switch, since Capistrano will check for that prompt in the output
|
|
142
|
+
# and will respond appropriately.
|
|
143
|
+
def authentication
|
|
144
|
+
return "" unless @new_resource.svn_username
|
|
145
|
+
result = "--username #{@new_resource.svn_username} "
|
|
146
|
+
result << "--password #{@new_resource.svn_password} "
|
|
147
|
+
result
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def scm(*args)
|
|
151
|
+
['svn', *args].compact.join(" ")
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'chef/provider/file'
|
|
20
|
+
require 'chef/mixin/template'
|
|
21
|
+
require 'chef/mixin/checksum'
|
|
22
|
+
require 'chef/mixin/find_preferred_file'
|
|
23
|
+
require 'chef/rest'
|
|
24
|
+
require 'chef/file_cache'
|
|
25
|
+
require 'uri'
|
|
26
|
+
require 'tempfile'
|
|
27
|
+
|
|
28
|
+
class Chef
|
|
29
|
+
class Provider
|
|
30
|
+
|
|
31
|
+
class Template < Chef::Provider::File
|
|
32
|
+
|
|
33
|
+
include Chef::Mixin::Checksum
|
|
34
|
+
include Chef::Mixin::Template
|
|
35
|
+
include Chef::Mixin::FindPreferredFile
|
|
36
|
+
|
|
37
|
+
def action_create
|
|
38
|
+
raw_template_file = nil
|
|
39
|
+
|
|
40
|
+
Chef::Log.debug("looking for template #{@new_resource.source} in cookbook #{cookbook_name.inspect}")
|
|
41
|
+
|
|
42
|
+
cache_file_name = "cookbooks/#{cookbook_name}/templates/default/#{@new_resource.source}"
|
|
43
|
+
template_cache_name = "#{cookbook_name}_#{@new_resource.source}"
|
|
44
|
+
|
|
45
|
+
if Chef::Config[:solo]
|
|
46
|
+
cache_file_name = solo_cache_file_name
|
|
47
|
+
else
|
|
48
|
+
raw_template_file = fetch_template_via_rest(cache_file_name, template_cache_name)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if template_updated?
|
|
52
|
+
Chef::Log.debug("Updating template for #{@new_resource} in the cache")
|
|
53
|
+
Chef::FileCache.move_to(raw_template_file.path, cache_file_name)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
template_file = render_with_context(cache_file_name)
|
|
57
|
+
|
|
58
|
+
update = false
|
|
59
|
+
|
|
60
|
+
if ::File.exists?(@new_resource.path)
|
|
61
|
+
@new_resource.checksum(self.checksum(template_file.path))
|
|
62
|
+
if @new_resource.checksum != @current_resource.checksum
|
|
63
|
+
Chef::Log.debug("#{@new_resource} changed from #{@current_resource.checksum} to #{@new_resource.checksum}")
|
|
64
|
+
Chef::Log.info("Updating #{@new_resource} at #{@new_resource.path}")
|
|
65
|
+
update = true
|
|
66
|
+
end
|
|
67
|
+
else
|
|
68
|
+
Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
|
|
69
|
+
update = true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if update
|
|
73
|
+
backup
|
|
74
|
+
FileUtils.cp(template_file.path, @new_resource.path)
|
|
75
|
+
@new_resource.updated = true
|
|
76
|
+
else
|
|
77
|
+
Chef::Log.debug("#{@new_resource} is unchanged")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
set_owner if @new_resource.owner != nil
|
|
81
|
+
set_group if @new_resource.group != nil
|
|
82
|
+
set_mode if @new_resource.mode != nil
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def action_create_if_missing
|
|
86
|
+
if ::File.exists?(@new_resource.path)
|
|
87
|
+
Chef::Log.debug("Template #{@new_resource} exists, taking no action.")
|
|
88
|
+
else
|
|
89
|
+
action_create
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def template_updated
|
|
96
|
+
@template_updated = true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def template_not_updated
|
|
100
|
+
@template_updated = false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def template_updated?
|
|
104
|
+
@template_updated
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def cookbook_name
|
|
108
|
+
@cookbook_name ||= (@new_resource.cookbook || @new_resource.cookbook_name)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def render_with_context(cache_file_name)
|
|
112
|
+
context = {}
|
|
113
|
+
context.merge!(@new_resource.variables)
|
|
114
|
+
context[:node] = @node
|
|
115
|
+
render_template(Chef::FileCache.load(cache_file_name), context)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def solo_cache_file_name
|
|
119
|
+
filename = find_preferred_file(
|
|
120
|
+
cookbook_name,
|
|
121
|
+
:template,
|
|
122
|
+
@new_resource.source,
|
|
123
|
+
@node[:fqdn],
|
|
124
|
+
@node[:platform],
|
|
125
|
+
@node[:platform_version]
|
|
126
|
+
)
|
|
127
|
+
Chef::Log.debug("Using local file for template:#{filename}")
|
|
128
|
+
Pathname.new(filename).relative_path_from(Pathname.new(Chef::Config[:file_cache_path])).to_s
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def fetch_template_via_rest(cache_file_name, template_cache_name)
|
|
132
|
+
if @node.run_state[:template_cache].has_key?(template_cache_name)
|
|
133
|
+
Chef::Log.debug("I have already fetched the template for #{@new_resource} once this run, not checking again.")
|
|
134
|
+
template_not_updated
|
|
135
|
+
return false
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
r = Chef::REST.new(Chef::Config[:template_url])
|
|
139
|
+
|
|
140
|
+
current_checksum = nil
|
|
141
|
+
|
|
142
|
+
if Chef::FileCache.has_key?(cache_file_name)
|
|
143
|
+
current_checksum = self.checksum(Chef::FileCache.load(cache_file_name, false))
|
|
144
|
+
else
|
|
145
|
+
Chef::Log.debug("Template #{@new_resource} is not in the template cache")
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
template_url = generate_url(
|
|
149
|
+
@new_resource.source,
|
|
150
|
+
"templates",
|
|
151
|
+
{
|
|
152
|
+
:checksum => current_checksum
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
begin
|
|
157
|
+
raw_template_file = r.get_rest(template_url, true)
|
|
158
|
+
template_updated
|
|
159
|
+
rescue Net::HTTPRetriableError => e
|
|
160
|
+
if e.response.kind_of?(Net::HTTPNotModified)
|
|
161
|
+
Chef::Log.debug("Cached template for #{@new_resource} is unchanged")
|
|
162
|
+
else
|
|
163
|
+
raise e
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# We have checked the cache for this template this run
|
|
168
|
+
@node.run_state[:template_cache][template_cache_name] = true
|
|
169
|
+
|
|
170
|
+
raw_template_file
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'chef/provider'
|
|
20
|
+
require 'chef/mixin/command'
|
|
21
|
+
require 'chef/resource/user'
|
|
22
|
+
require 'etc'
|
|
23
|
+
|
|
24
|
+
class Chef
|
|
25
|
+
class Provider
|
|
26
|
+
class User < Chef::Provider
|
|
27
|
+
|
|
28
|
+
include Chef::Mixin::Command
|
|
29
|
+
|
|
30
|
+
attr_accessor :user_exists, :locked
|
|
31
|
+
|
|
32
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
|
33
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
|
34
|
+
@user_exists = true
|
|
35
|
+
@locked = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def convert_group_name
|
|
39
|
+
if @new_resource.gid.is_a? String
|
|
40
|
+
@new_resource.gid Etc.getgrnam(@new_resource.gid).gid
|
|
41
|
+
end
|
|
42
|
+
rescue ArgumentError => e
|
|
43
|
+
raise Chef::Exceptions::User, "Couldn't lookup integer GID for group name #{@new_resource.gid}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def load_current_resource
|
|
47
|
+
@current_resource = Chef::Resource::User.new(@new_resource.name)
|
|
48
|
+
@current_resource.username(@new_resource.username)
|
|
49
|
+
|
|
50
|
+
user_info = nil
|
|
51
|
+
begin
|
|
52
|
+
user_info = Etc.getpwnam(@new_resource.username)
|
|
53
|
+
rescue ArgumentError => e
|
|
54
|
+
@user_exists = false
|
|
55
|
+
Chef::Log.debug("User #{@new_resource.username} does not exist")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if user_info
|
|
59
|
+
@current_resource.uid(user_info.uid)
|
|
60
|
+
@current_resource.gid(user_info.gid)
|
|
61
|
+
@current_resource.comment(user_info.gecos)
|
|
62
|
+
@current_resource.home(user_info.dir)
|
|
63
|
+
@current_resource.shell(user_info.shell)
|
|
64
|
+
@current_resource.password(user_info.passwd)
|
|
65
|
+
|
|
66
|
+
if @new_resource.password && @current_resource.password == 'x'
|
|
67
|
+
begin
|
|
68
|
+
require 'shadow'
|
|
69
|
+
rescue LoadError
|
|
70
|
+
Chef::Log.error("You must have ruby-shadow installed for password support!")
|
|
71
|
+
raise Chef::Exceptions::MissingLibrary, "You must have ruby-shadow installed for password support!"
|
|
72
|
+
else
|
|
73
|
+
shadow_info = Shadow::Passwd.getspnam(@new_resource.username)
|
|
74
|
+
@current_resource.password(shadow_info.sp_pwdp)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
if @new_resource.gid
|
|
79
|
+
convert_group_name
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
@current_resource
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Check to see if the user needs any changes
|
|
87
|
+
#
|
|
88
|
+
# === Returns
|
|
89
|
+
# <true>:: If a change is required
|
|
90
|
+
# <false>:: If the users are identical
|
|
91
|
+
def compare_user
|
|
92
|
+
[ :uid, :gid, :comment, :home, :shell, :password ].any? do |user_attrib|
|
|
93
|
+
!@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib) != @current_resource.send(user_attrib)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def action_create
|
|
98
|
+
case @user_exists
|
|
99
|
+
when false
|
|
100
|
+
create_user
|
|
101
|
+
Chef::Log.info("Created #{@new_resource}")
|
|
102
|
+
@new_resource.updated = true
|
|
103
|
+
else
|
|
104
|
+
if compare_user
|
|
105
|
+
manage_user
|
|
106
|
+
Chef::Log.info("Altered #{@new_resource}")
|
|
107
|
+
@new_resource.updated = true
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def action_remove
|
|
113
|
+
if @user_exists
|
|
114
|
+
remove_user
|
|
115
|
+
@new_resource.updated = true
|
|
116
|
+
Chef::Log.info("Removed #{@new_resource}")
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def action_manage
|
|
121
|
+
if @user_exists && compare_user
|
|
122
|
+
manage_user
|
|
123
|
+
@new_resource.updated = true
|
|
124
|
+
Chef::Log.info("Managed #{@new_resource}")
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def action_modify
|
|
129
|
+
if @user_exists
|
|
130
|
+
if compare_user
|
|
131
|
+
manage_user
|
|
132
|
+
@new_resource.updated = true
|
|
133
|
+
Chef::Log.info("Modified #{@new_resource}")
|
|
134
|
+
end
|
|
135
|
+
else
|
|
136
|
+
raise Chef::Exceptions::User, "Cannot modify #{@new_resource} - user does not exist!"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def action_lock
|
|
141
|
+
if @user_exists
|
|
142
|
+
if check_lock() == false
|
|
143
|
+
lock_user
|
|
144
|
+
@new_resource.updated = true
|
|
145
|
+
Chef::Log.info("Locked #{@new_resource}")
|
|
146
|
+
else
|
|
147
|
+
Chef::Log.debug("No need to lock #{@new_resource}")
|
|
148
|
+
end
|
|
149
|
+
else
|
|
150
|
+
raise Chef::Exceptions::User, "Cannot lock #{@new_resource} - user does not exist!"
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def action_unlock
|
|
155
|
+
if @user_exists
|
|
156
|
+
if check_lock() == true
|
|
157
|
+
unlock_user
|
|
158
|
+
@new_resource.updated = true
|
|
159
|
+
Chef::Log.info("Unlocked #{@new_resource}")
|
|
160
|
+
else
|
|
161
|
+
Chef::Log.debug("No need to unlock #{@new_resource}")
|
|
162
|
+
end
|
|
163
|
+
else
|
|
164
|
+
raise Chef::Exceptions::User, "Cannot unlock #{@new_resource} - user does not exist!"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|