From f56d2d7888be1a27d7ef05d850afdc4e9dbb464a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 20 Dec 2021 12:39:15 +0100 Subject: initial draft of a minimal puppet config template --- .../production/modules/apt/tasks/init.rb | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 code/environments/production/modules/apt/tasks/init.rb (limited to 'code/environments/production/modules/apt/tasks/init.rb') diff --git a/code/environments/production/modules/apt/tasks/init.rb b/code/environments/production/modules/apt/tasks/init.rb new file mode 100755 index 0000000..d256468 --- /dev/null +++ b/code/environments/production/modules/apt/tasks/init.rb @@ -0,0 +1,24 @@ +#!/opt/puppetlabs/puppet/bin/ruby +require 'json' +require 'open3' +require 'puppet' + +def apt_get(action) + cmd = ['apt-get', action] + cmd << ' -y' if action == 'upgrade' + 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 -- cgit v1.2.3