File: init.rb

package info (click to toggle)
puppet-module-puppetlabs-apt 9.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 572 kB
  • sloc: ruby: 438; sh: 31; makefile: 2
file content (34 lines) | stat: -rwxr-xr-x 807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/opt/puppetlabs/puppet/bin/ruby
# frozen_string_literal: true

require 'json'
require 'open3'
require 'puppet'

def apt_get(action)
  cmd = ['apt-get', action]
  cmd << '-y' if ['upgrade', 'dist-upgrade', 'autoremove'].include?(action)
  if ['upgrade', 'dist-upgrade'].include?(action)
    ENV['DEBIAN_FRONTEND'] = 'noninteractive'
    cmd << '-o'
    cmd << 'Dpkg::Options="--force-confdef"'
    cmd << '-o'
    cmd << 'Dpkg::Options="--force-confold"'
  end
  stdout, stderr, status = Open3.capture3(*cmd)
  raise Puppet::Error, stderr if status != 0

  { status: stdout.strip }
end

params = JSON.parse($stdin.read)
action = params['action']

begin
  result = apt_get(action)
  puts result.to_json
  exit 0
rescue Puppet::Error => e
  puts({ status: 'failure', error: e.message }.to_json)
  exit 1
end