summaryrefslogtreecommitdiff
path: root/lib/chef/mixin
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-05-29 15:56:20 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-05-29 16:20:17 -0700
commitdeea4f3b00a6bd18beba85c05ddec93a143cdb8b (patch)
tree80514eafa5ed418ed047117b058a0ced7548c792 /lib/chef/mixin
parentb6488236ef24b9c44295deac78b7bd2498e372ba (diff)
downloadchef-deea4f3b00a6bd18beba85c05ddec93a143cdb8b.tar.gz
Target mode for systemd service helper
Makes it so that local cookbook can bounce a remote service over train/ssh/whatever. Works at least for ubuntu. Introduces a fairly rudimentary TrainHelpers class, using some inspiration from ohbye. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r--lib/chef/mixin/shell_out.rb3
-rw-r--r--lib/chef/mixin/train_helpers.rb44
2 files changed, 45 insertions, 2 deletions
diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb
index 6c2db85dfe..9f7b18eace 100644
--- a/lib/chef/mixin/shell_out.rb
+++ b/lib/chef/mixin/shell_out.rb
@@ -17,7 +17,6 @@
require "mixlib/shellout" unless defined?(Mixlib::ShellOut::DEFAULT_READ_TIMEOUT)
require_relative "path_sanity"
-require "shellwords" unless defined?(Shellwords)
class Chef
module Mixin
@@ -160,7 +159,7 @@ class Chef
def self.shell_out_command(*args, **options)
if Chef::Config.target_mode?
- FakeShellOut.new(args, options, transport_connection.run_command(Shellwords.join(" "))) # FIXME: train should accept run_command(*args)
+ FakeShellOut.new(args, options, transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
else
cmd = if options.empty?
Mixlib::ShellOut.new(*args)
diff --git a/lib/chef/mixin/train_helpers.rb b/lib/chef/mixin/train_helpers.rb
new file mode 100644
index 0000000000..b37511bdea
--- /dev/null
+++ b/lib/chef/mixin/train_helpers.rb
@@ -0,0 +1,44 @@
+#--
+# Author:: Lamont Granquist <lamont@chef.io>
+# Copyright:: Copyright 2010-2018, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require "stringio" unless defined?(StringIO)
+
+class Chef
+ module Mixin
+ module TrainHelpers
+ def file_exist?(*args)
+ if Chef::Config.target_mode?
+ Chef.run_context.transport_connection.file(args[0]).exist?
+ else
+ File.exist?(*args)
+ end
+ end
+
+ # XXX: modifications to the StringIO won't get written back
+ def file_open(*args, &block)
+ if Chef::Config.target_mode?
+ content = Chef.run_context.transport_connection.file(args[0]).content
+ string_io = StringIO.new content
+ yield string_io if block_given?
+ string_io
+ else
+ File.open(*args, &block)
+ end
+ end
+ end
+ end
+end