Skip to content

Commit 9d9fa34

Browse files
committed
allow passing extra_env when calling commands
1 parent 67702be commit 9d9fa34

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

hooks/boot/01-kafo-hook-extensions.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def log_and_say(level, message, do_say = true, do_log = true)
101101
Kafo::KafoConfigure.logger.send(level, message) if do_log
102102
end
103103

104-
def execute!(command, do_say = true, do_log = true)
105-
stdout_stderr, status = execute_command(command, do_say, do_log)
104+
def execute!(command, do_say = true, do_log = true, extra_env = {})
105+
stdout_stderr, status = execute_command(command, do_say, do_log, extra_env)
106106

107107
if stdout_stderr.nil?
108108
log_and_say(:error, "Command #{command} not found", do_say, do_log)
@@ -115,21 +115,21 @@ def execute!(command, do_say = true, do_log = true)
115115
end
116116
end
117117

118-
def execute_as!(user, command, do_say = true, do_log = true)
118+
def execute_as!(user, command, do_say = true, do_log = true, extra_env = {})
119119
runuser_command = "runuser -l #{user} -c '#{command}'"
120-
execute!(runuser_command, do_say, do_log)
120+
execute!(runuser_command, do_say, do_log, extra_env)
121121
end
122122

123-
def execute(command, do_say, do_log)
124-
_stdout_stderr, status = execute_command(command, do_say, do_log)
123+
def execute(command, do_say, do_log, extra_env = {})
124+
_stdout_stderr, status = execute_command(command, do_say, do_log, extra_env)
125125
status
126126
end
127127

128-
def execute_command(command, do_say, do_log)
128+
def execute_command(command, do_say, do_log, extra_env = {})
129129
log_and_say(:debug, "Executing: #{command}", do_say, do_log)
130130

131131
begin
132-
stdout_stderr, status = Open3.capture2e(*Kafo::PuppetCommand.format_command(command))
132+
stdout_stderr, status = Open3.capture2e(*Kafo::PuppetCommand.format_command(command, extra_env))
133133
rescue Errno::ENOENT
134134
return [nil, false]
135135
end

0 commit comments

Comments
 (0)