简体   繁体   中英

puppet: Why is the file resource not created?

I have the following code on a manifest:

  $shutdown_script = '/etc/init.d/puppet-report-shutdown'                                                                                                       
  file { 'shutdown-script':                                                                                                                                     
    ensure => present,                                                                                                                                          
    path   => $shutdown_script,                                                                                                                                 
    owner  => 'root',                                                                                                                                           
    group  => 'root',                                                                                                                                           
    mode   => '0755',                                                                                                                                           
    source => 'puppet:///modules/puppet_agent/puppet-report-shutdown.sh'                                                                                        
  }                                                                                                                                                             

  exec { 'chkconfig':                                                                                                                                           
    command => "chkconfig --add ${shutdown_script}",                                                                                                            
    require => File['shutdown-script']                                                                                                                          
  }  

The exec code is failing, because it cannot find the script:

`Error: Failed to apply catalog: Validation of Exec[chkconfig] failed: 'chkconfig --add /etc/init.d/puppet-report-shutdown' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50

The file resource is not being created, but I can't find why. I tried running the agent with --debug , but there's nothing useful there (to the best of my knoledge, at least):

Debug: /File[shutdown-script]/seluser: Found seluser default 'system_u' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/selrole: Found selrole default 'object_r' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/seltype: Found seltype default 'initrc_exec_t' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/selrange: Found selrange default 's0' for /etc/init.d/puppet-report-shutdown

Any help would be appreciated. Thanks

There are actually a few problems here, but let us go through them sequentially.

  1. ensure => file

The file resource should be specifying an ensure of file instead of present. That instructs Puppet more specifically as to what the type and content of the file on the node should be:

file { 'shutdown-script':                                                                                                                                     
  ensure => file,                                                                                                                                          
  path   => $shutdown_script,                                                                                                                                 
  owner  => 'root',                                                                                                                                           
  group  => 'root',                                                                                                                                           
  mode   => '0755',                                                                                                                                           
  source => 'puppet:///modules/puppet_agent/puppet-report-shutdown.sh'                                                                                        
}
  1. command => "/sbin/chkconfig --add ${shutdown_script}"

The exec resource either requires a full path to the command, or you can specify lookup paths with the path attribute. In this case, the easiest solution is to provide the full path:

exec { 'chkconfig':                                                                                                                                           
  command => "/sbin/chkconfig --add ${shutdown_script}",                                                                                                            
  require => File['shutdown-script']                                                                                                                          
}

This is actually your root cause here. The file is not being created because the Puppet agent is never actually applying your catalog because you have a compilation error:

Error: Failed to apply catalog: Validation of Exec[chkconfig] failed: 'chkconfig --add /etc/init.d/puppet-report-shutdown' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50

  1. service

Instead of using exec to add the service, you can add and enable it with the enable attribute in the service resource. I would also recommend changing the require metaparameter to subscribe , because otherwise your changes to the service script will not be picked up by the system's service manager. With subscribe , Puppet will instruct the system to recognize and reconfigure the service if the script changes. This is also a problem with your current exec resource.

service { 'puppet-report-shutdown':
  enable    => true,
  subscribe => File['shutdown-script'],
}

The error message clearly states the issue.

Puppet needs the command to be " either fully qualified or a search path for the command must be provided ".

Either fully qualify your command like this:

command => "/usr/sbin/chkconfig --add ${shutdown_script}",

or specify some path like this (usually when you're not sure where the command lies):

path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM