Bug #15080

puppet provider/exec.rb issue on puppet 2.7.14/2.7.16

Added by jayendren maduray about 1 year ago. Updated 10 months ago.

Status:Requires CLA to be signedStart date:06/18/2012
Priority:NormalDue date:
Assignee:jayendren maduray% Done:

0%

Category:exec
Target version:-
Affected Puppet version: Branch:
Keywords:

Description

  • Puppet Versions: 2.7.14_½.7.16
  • Operating System: FreeBSD
  • Steps to Reproduce:
  • Using the following definition that is used to add/update entries in /etc/rc.conf
define shell_config($file, $key, $value, $ensure = 'present')
{
  case $ensure {
    default: { err ( "unknown ensure value ${ensure}" ) }
    present: {
      exec {
        "shell_config_unique_$ensure '$file$key'":
         path => ["/sbin","/bin","/usr/sbin","/usr/bin"],
          unless => "test `grep -cE '^[ \t]*$key=' -- $file` -le 1",
          command => "sed -i '' -e '/$key=\".*\"/d' $file";
        "shell_config_create_$ensure '$file$key'":
         path => ["/sbin","/bin","/usr/sbin","/usr/bin"],
          unless => "grep -qE '^[ \t]*$key=' -- $file",
          command => "echo 'testing!'; printf '%s=\"%s\"\n' '$key' '$value' >> '${file}'";
        "shell_config_update_$ensure '$file$key'":
          unless => "grep -qE '^[ \t]*$key=\"$value\"' -- $file",
          command => "sed -i '' -e 's/$key=\".*\"/$key=\"$value\"/' $file";
      }
    }
    absent: {
      exec {  "shell_config_delete_$ensure $file$key":
         path => ["/sbin","/bin","/usr/sbin","/usr/bin"],
          onlyif => "grep -qE '^[ \t]*$key=' -- $file",
          command => "sed -i '' -e '/$key=\".*\"/d' $file";
      }
    }
  }
}

define rc_conf($value)
{
  shell_config { "rc_conf_local_${name}":
    file => "/etc/rc.conf",
    key => $name,
    value => $value;
  }
}
  • class entry in nodefile: rc_conf { vmware_guest_vmhgfs_enable: value => “YES” }

  • Expected Results:

  • If the entry is not present /etc/rc.conf, puppet should add the entry (working on puppet-2.7.10) *
notice: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_update_present '/etc/rc.confvmware_guest_vmhgfs_enable']/returns: executed successfully
debug: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_update_present '/etc/rc.confvmware_guest_vmhgfs_enable']: The container Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable] will propagate my refresh event
debug: Exec[shell_config_unique_present '/etc/rc.confvmware_guest_vmhgfs_enable'](provider=posix): Executing check 'test `grep -cE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf` -le 1'
debug: Executing 'test `grep -cE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf` -le 1'
debug: Exec[shell_config_create_present '/etc/rc.confvmware_guest_vmhgfs_enable'](provider=posix): Executing check 'grep -qE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf'
debug: Executing 'grep -qE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf'
debug: Exec[shell_config_create_present '/etc/rc.confvmware_guest_vmhgfs_enable'](provider=posix): Executing 'printf '%s="%s"
' 'vmware_guest_vmhgfs_enable' 'YES' >> '/etc/rc.conf''
debug: Executing 'printf '%s="%s"
' 'vmware_guest_vmhgfs_enable' 'YES' >> '/etc/rc.conf''
notice: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_create_present '/etc/rc.confvmware_guest_vmhgfs_enable']/returns: executed successfully
  • Actual Results:
  • puppet 2.7.14_1 and puppet 2.7.16:
notice: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_update_present '/etc/rc.confvmware_guest_vmhgfs_enable']/returns: executed successfully
debug: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_update_present '/etc/rc.confvmware_guest_vmhgfs_enable']: The container Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable] will propagate my refresh event
debug: Exec[shell_config_unique_present '/etc/rc.confvmware_guest_vmhgfs_enable'](provider=posix): Executing check 'test `grep -cE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf` -le 1'
debug: Executing 'test `grep -cE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf` -le 1'
debug: Exec[shell_config_create_present '/etc/rc.confvmware_guest_vmhgfs_enable'](provider=posix): Executing check 'grep -qE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf'
debug: Executing 'grep -qE '^[ ]*vmware_guest_vmhgfs_enable=' -- /etc/rc.conf'
err: /Stage[main]/Virtualguest/Rc_conf[vmware_guest_vmhgfs_enable]/Shell_config[rc_conf_local_vmware_guest_vmhgfs_enable]/Exec[shell_config_create_present '/etc/rc.confvmware_guest_vmhgfs_enable']/returns: change from notrun to 0 failed: Could not find command ' '
  • Notes:
  • Resolved by using provider/exec.rb from puppet 2.7.10
  • File: /usr/local/lib/ruby/site_ruby/1.8/puppet/provider/exec.rb *
--- /usr/local/lib/ruby/site_ruby/1.8/puppet/provider/exec.rb   2012-06-18 11:27:07.000000000 +0200
+++ /root/provider_exec.rb  2012-06-18 11:26:20.000000000 +0200
@@ -1,3 +1,6 @@
+require 'puppet/provider'
+require 'puppet/util/execution'
+
 class Puppet::Provider::Exec < Puppet::Provider
   include Puppet::Util::Execution
 
@@ -63,9 +66,11 @@
   end
 
   def extractexe(command)
-    # easy case: command was quoted
-    if command =~ /^"([^"]+)"/
-      $1
+    if command.is_a? Array
+      command.first
+    elsif match = /^"([^"]+)"|^'([^']+)'/.match(command)
+      # extract whichever of the two sides matched the content.
+      match[1] or match[2]
     else
       command.split(/ /)[0]
     end

puppet_provider_exec_rb_15080.txt Magnifier - provider/exec.rb diff (799 Bytes) jayendren maduray, 06/18/2012 02:44 am

History

#2 Updated by James Turnbull about 1 year ago

  • Description updated (diff)

#3 Updated by James Turnbull 10 months ago

  • Status changed from Unreviewed to Requires CLA to be signed
  • Assignee set to jayendren maduray

Thanks for your patch! Could you please read our contribution guidelines (https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md) and sign a CLA. It’d be awesome if you could submit this as a pull request.

Thanks again!

Also available in: Atom PDF