From ec4abb2573133af439666160d9c873fceea4b4c9 Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov Date: Mon, 6 Mar 2017 15:20:20 +0300 Subject: [PATCH] Add command_prefix field to puppet mcagent This will allow to run puppet with environment variables. E.g. FACTER_foo=bar puppet apply ... Change-Id: I1e435262e810ead46689078513607f6a99a19043 Implements: blueprint get-rid-cobbler-dnsmasq (cherry picked from commit c734b030420c8ad78038ec5790e606f0c24ef616) --- bindep.txt | 0 lib/astute/mclients/puppet_mclient.rb | 1 + lib/astute/tasks/puppet.rb | 1 + mcagents/puppetd.ddl | 9 +++++++++ mcagents/puppetd.rb | 2 ++ spec/unit/mclients/puppet_mclient_spec.rb | 2 ++ 6 files changed, 15 insertions(+) create mode 100644 bindep.txt diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 00000000..e69de29b diff --git a/lib/astute/mclients/puppet_mclient.rb b/lib/astute/mclients/puppet_mclient.rb index d50b9309..65abdf48 100644 --- a/lib/astute/mclients/puppet_mclient.rb +++ b/lib/astute/mclients/puppet_mclient.rb @@ -97,6 +97,7 @@ module Astute :manifest => @options['puppet_manifest'], :modules => @options['puppet_modules'], :cwd => @options['cwd'], + :command_prefix => @options['command_prefix'], :puppet_noop_run => @options['puppet_noop_run'], ).first return result[:statuscode] == 0, result[:statusmsg] diff --git a/lib/astute/tasks/puppet.rb b/lib/astute/tasks/puppet.rb index 3d8d8795..92ec697c 100644 --- a/lib/astute/tasks/puppet.rb +++ b/lib/astute/tasks/puppet.rb @@ -43,6 +43,7 @@ module Astute 'retries' => Astute.config.puppet_retries, 'puppet_manifest' => '/etc/puppet/manifests/site.pp', 'puppet_modules' => Astute.config.puppet_module_path, + 'command_prefix' => '', 'cwd' => Astute.config.shell_cwd, 'timeout' => Astute.config.puppet_timeout, 'debug' => false, diff --git a/mcagents/puppetd.ddl b/mcagents/puppetd.ddl index 5a6caa64..44c27ad9 100644 --- a/mcagents/puppetd.ddl +++ b/mcagents/puppetd.ddl @@ -97,6 +97,15 @@ action "runonce", :description => "Invoke a single puppet run" do :default => true, :optional => true + input :command_prefix, + :prompt => "Puppet command prefix (allows to run puppet with variables)", + :description => "Allows to run puppet with variables (e.g. FACTER_foo=bar)", + :type => :string, + :validation => :shellsafe, + :default => '', + :optional => true, + :maxlength => 0 + output :output, :description => "Output from puppet", :display_as => "Output" diff --git a/mcagents/puppetd.rb b/mcagents/puppetd.rb index 3c2e74e7..df95b72f 100644 --- a/mcagents/puppetd.rb +++ b/mcagents/puppetd.rb @@ -202,7 +202,9 @@ module MCollective cwd = request.fetch(:cwd, '/') manifest = request.fetch(:manifest, '/etc/puppet/manifests/site.pp') module_path = request.fetch(:modules, '/etc/puppet/modules') + command_prefix = request.fetch(:command_prefix, '') cmd = [ + command_prefix, @puppetd, "-c #{cwd}", @puppetd_agent, diff --git a/spec/unit/mclients/puppet_mclient_spec.rb b/spec/unit/mclients/puppet_mclient_spec.rb index c9a38054..2979e69f 100644 --- a/spec/unit/mclients/puppet_mclient_spec.rb +++ b/spec/unit/mclients/puppet_mclient_spec.rb @@ -35,6 +35,7 @@ describe Astute::PuppetMClient do let(:options) do { 'cwd' => '/etc/puppet/mainfest/test', + 'command_prefix' => '', 'puppet_manifest' => 'test_manifest.pp', 'puppet_noop_run' => false, 'raw_report' => true, @@ -200,6 +201,7 @@ describe Astute::PuppetMClient do :manifest => options['puppet_manifest'], :modules => options['puppet_modules'], :cwd => options['cwd'], + :command_prefix => options['command_prefix'], :puppet_noop_run => options['puppet_noop_run'], ).returns([:statuscode => 0])