Merge pull request #832 from aboks/apt-task
[puppet-modules/puppetlabs-apt.git] / tasks / init.rb
index 5db86ebb0c00b0fca3ca3883e6156129287306cc..f8ca85e2f5d81126a49146e785622ba4551cb0b2 100755 (executable)
@@ -4,10 +4,10 @@ require 'open3'
 require 'puppet'
 
 def apt_get(action)
-  cmd_string = "apt-get #{action}"
-  cmd_string << ' -y' if  action == 'upgrade'
-  stdout, stderr, status = Open3.capture3(cmd_string)
-  raise Puppet::Error, stderr if status != 0
+  cmd = ['apt-get', action]
+  cmd << '-y' if ['upgrade', 'dist-upgrade', 'autoremove'].include?(action)
+  stdout, stderr, status = Open3.capture3(*cmd)
+  raise Puppet::Error, stderr if status != 0 # rubocop:disable GetText/DecorateFunctionMessage
   { status: stdout.strip }
 end