@@ -138,26 +138,34 @@ def config_print(*keys)
138138 end
139139 end
140140
141+ def noop ( params )
142+ params [ 'noop' ] == true ? '--noop' : ''
143+ end
144+
145+ def environment ( params )
146+ params [ 'environment' ] . length > 1 ? "--environment=#{ params [ 'environment' ] } " : ''
147+ end
148+
141149 # Attempts to run the Puppet agent, returning the mtime for the last run report
142150 # and the exit code from the Puppet agent run.
143- def try_run ( last_run_report )
151+ def try_run ( last_run_report , params )
144152 start_time = get_start_time ( last_run_report )
145153
146- command = [ puppet_bin , 'agent' , '-t' , '--color' , 'false' ]
154+ command = [ puppet_bin , 'agent' , '-t' , '--color' , 'false' , noop ( params ) , environment ( params ) ]
147155
148156 options = {
149157 failonfail : false ,
150158 custom_environment : get_env_fix_up ,
151159 override_locale : false
152160 }
153161
154- run_result = Puppet ::Util ::Execution . execute ( command , options )
162+ run_result = Puppet ::Util ::Execution . execute ( command . reject ( & :empty? ) , options )
155163
156164 [ start_time , run_result ]
157165 end
158166
159167 # Runs the Puppet agent and returns the last run report.
160- def run
168+ def run ( params )
161169 unless puppet_bin_present?
162170 return error_result (
163171 'puppet_agent/no-puppet-bin-error' ,
@@ -177,7 +185,7 @@ def run
177185
178186 # Initially ignore the lockfile. It might be out-dated, so we give Puppet a chance
179187 # to clean it up and run.
180- start_time , run_result = try_run ( last_run_report )
188+ start_time , run_result = try_run ( last_run_report , params )
181189 if run_result . nil?
182190 return error_result (
183191 'puppet_agent/fail-to-start-error' ,
@@ -204,7 +212,7 @@ def run
204212 if running? ( lockfile )
205213 wait_for_lockfile ( lockfile )
206214
207- start_time , run_result = try_run ( last_run_report )
215+ start_time , run_result = try_run ( last_run_report , params )
208216 if run_result . nil?
209217 return error_result (
210218 'puppet_agent/fail-to-start-error' ,
@@ -237,5 +245,5 @@ def run
237245
238246if __FILE__ == $PROGRAM_NAME
239247 runner = PuppetAgent ::Runner . new
240- puts JSON . dump ( runner . run )
248+ puts JSON . dump ( runner . run ( params ) )
241249end
0 commit comments