Bug #1008
Undefined method error in pfile/source.rb when source for file resource does not exist
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | 0.24.0 | |||
| Affected Puppet version: | 0.25.4 | Branch: | ||
| Keywords: | ||||
| Votes: | 0 |
Description
This is the offending configuration snippet:
file { "/etc/apache2/sites-available/dev-www":
ensure => present,
mode => 640,
owner => root,
group => root,
source => '/home/jbq/_svn/conf/apache/sites/dev-www'
}
This is the error puppetd reports:
# ruby --debug /usr/sbin/puppetd --test info: Caching catalog at /var/lib/puppet/state/localconfig.yaml notice: Starting catalog run /usr/lib/ruby/1.8/puppet/node.rb:107: warning: instance variable @environment not initialized Exception @NoMethodError' at /usr/lib/ruby/1.8/puppet/type/pfile/source.rb:250 - undefined method @[]' for nil:NilClass Exception @Puppet::Error' at /usr/lib/ruby/1.8/puppet/property.rb:174 - Could not set present on ensure: undefined method @[]' for nil:NilClass at /home/jbq/_svn/conf/puppet/manifests/site.pp:39 err: //Node[ovh1]/apache/File[/etc/apache2/sites-available/dev-www]/ensure: change from absent to present failed: Could not set present on ensure: undefined method @[]' for nil:NilClass at /home/jbq/_svn/conf/puppet/manifests/site.pp:39
History
Updated by AJ Christensen over 4 years ago
unable to replicate
root@puppet:/tmp# cat test.pp
file { "/tmp/etc/apache2/sites-available/dev-www":
ensure => present,
mode => 640,
owner => root,
group => root,
source => '/tmp/home/jbq/_svn/conf/apache/sites/dev-www'
}
root@puppet:/tmp# puppet --debug test.pp
info: Loading fact interfaces
info: Loading fact netmask
info: Loading fact acpi_available
info: mount[localhost]: Mounted /
info: mount[modules]: Mounted
info: mount[plugins]: Mounted
debug: Creating default schedules
debug: Finishing transaction -608175148 with 0 changes
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: File does not exist
debug: Finishing transaction -609573328 with 0 changes
debug: /File[/tmp/home/jbq/_svn/conf/apache/sites/dev-www]/checksum: Initializing checksum hash
debug: /File[/tmp/home/jbq/_svn/conf/apache/sites/dev-www]: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Changing ensure
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: 1 change(s)
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/checksum: Initializing checksum hash
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077
notice: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/ensure: created
debug: Finishing transaction -609406498 with 1 changes
Updated by Jean-Baptiste Quenot over 4 years ago
This is the output I get with the undocumented —trace option:
Exception @NoMethodError' at /usr/lib/ruby/1.8/puppet/type/pfile/source.rb:250 - undefined method @[]' for nil:NilClass /usr/lib/ruby/1.8/puppet/type/pfile/source.rb:250:in @sync' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:47:in @set_file' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:59:in @set_present' /usr/lib/ruby/1.8/puppet/property.rb:164:in @send' /usr/lib/ruby/1.8/puppet/property.rb:164:in @call_valuemethod' /usr/lib/ruby/1.8/puppet/property.rb:350:in @set' /usr/lib/ruby/1.8/puppet/property.rb:422:in @sync' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:168:in @sync' /usr/lib/ruby/1.8/puppet/propertychange.rb:81:in @go' /usr/lib/ruby/1.8/puppet/propertychange.rb:109:in @forward' /usr/lib/ruby/1.8/puppet/transaction.rb:119:in @apply_changes' /usr/lib/ruby/1.8/puppet/transaction.rb:111:in @collect' /usr/lib/ruby/1.8/puppet/transaction.rb:111:in @apply_changes' /usr/lib/ruby/1.8/puppet/transaction.rb:83:in @apply' /usr/lib/ruby/1.8/puppet/transaction.rb:240:in @eval_resource' /usr/lib/ruby/1.8/puppet/util.rb:444:in @thinmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:443:in @thinmark' /usr/lib/ruby/1.8/puppet/transaction.rb:239:in @eval_resource' /usr/lib/ruby/1.8/puppet/transaction.rb:311:in @evaluate' /usr/lib/ruby/1.8/puppet/util.rb:444:in @thinmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:443:in @thinmark' /usr/lib/ruby/1.8/puppet/transaction.rb:310:in @evaluate' /usr/lib/ruby/1.8/puppet/transaction.rb:304:in @collect' /usr/lib/ruby/1.8/puppet/transaction.rb:304:in @evaluate' /usr/lib/ruby/1.8/puppet/node/catalog.rb:102:in @apply' /usr/lib/ruby/1.8/puppet/network/client/master.rb:260:in @run' /usr/lib/ruby/1.8/puppet/util.rb:212:in @benchmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:211:in @benchmark' /usr/lib/ruby/1.8/puppet/network/client/master.rb:259:in @run' /usr/lib/ruby/1.8/sync.rb:229:in @synchronize' /usr/lib/ruby/1.8/puppet/network/client/master.rb:241:in @run' /usr/sbin/puppetd:429 Exception @Puppet::Error' at /usr/lib/ruby/1.8/puppet/property.rb:174 - Could not set present on ensure: undefined method @[]' for nil:NilClass at /home/jbq/_svn/conf/puppet/manifests/site.pp:39 /usr/lib/ruby/1.8/puppet/type/pfile/source.rb:250:in @sync' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:47:in @set_file' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:59:in @set_present' /usr/lib/ruby/1.8/puppet/property.rb:164:in @send' /usr/lib/ruby/1.8/puppet/property.rb:164:in @call_valuemethod' /usr/lib/ruby/1.8/puppet/property.rb:350:in @set' /usr/lib/ruby/1.8/puppet/property.rb:422:in @sync' /usr/lib/ruby/1.8/puppet/type/pfile/ensure.rb:168:in @sync' /usr/lib/ruby/1.8/puppet/propertychange.rb:81:in @go' /usr/lib/ruby/1.8/puppet/propertychange.rb:109:in @forward' /usr/lib/ruby/1.8/puppet/transaction.rb:119:in @apply_changes' /usr/lib/ruby/1.8/puppet/transaction.rb:111:in @collect' /usr/lib/ruby/1.8/puppet/transaction.rb:111:in @apply_changes' /usr/lib/ruby/1.8/puppet/transaction.rb:83:in @apply' /usr/lib/ruby/1.8/puppet/transaction.rb:240:in @eval_resource' /usr/lib/ruby/1.8/puppet/util.rb:444:in @thinmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:443:in @thinmark' /usr/lib/ruby/1.8/puppet/transaction.rb:239:in @eval_resource' /usr/lib/ruby/1.8/puppet/transaction.rb:311:in @evaluate' /usr/lib/ruby/1.8/puppet/util.rb:444:in @thinmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:443:in @thinmark' /usr/lib/ruby/1.8/puppet/transaction.rb:310:in @evaluate' /usr/lib/ruby/1.8/puppet/transaction.rb:304:in @collect' /usr/lib/ruby/1.8/puppet/transaction.rb:304:in @evaluate' /usr/lib/ruby/1.8/puppet/node/catalog.rb:102:in @apply' /usr/lib/ruby/1.8/puppet/network/client/master.rb:260:in @run' /usr/lib/ruby/1.8/puppet/util.rb:212:in @benchmark' /usr/lib/ruby/1.8/benchmark.rb:293:in @measure' /usr/lib/ruby/1.8/benchmark.rb:307:in @realtime' /usr/lib/ruby/1.8/puppet/util.rb:211:in @benchmark' /usr/lib/ruby/1.8/puppet/network/client/master.rb:259:in @run' /usr/lib/ruby/1.8/sync.rb:229:in @synchronize' /usr/lib/ruby/1.8/puppet/network/client/master.rb:241:in @run' /usr/sbin/puppetd:429 err: //Node[ovh1]/apache/File[/etc/apache2/sites-available/dev-www]/ensure: change from absent to present failed: Could not set present on ensure: undefined method @[]' for nil:NilClass at /home/jbq/_svn/conf/puppet/manifests/site.pp:39
Updated by Jean-Baptiste Quenot over 4 years ago
OK, I missed an important point: this is when the file does not exist, sorry for not being clear. The error message has to be improved.
This patch will report a better error message:
--- /home/jbq/packages/puppet/trunk/lib/puppet/type/pfile/source.rb 2008-01-09 11:29:22.000000000 +0100
+++ /usr/lib/ruby/1.8/puppet/type/pfile/source.rb 2008-01-15 10:20:46.000000000 +0100
@@ -247,6 +247,9 @@
end
def sync
+ unless described?
+ raise Puppet::Error, "No valid source found"
+ end
contents = @stats[:_remote_content] || get_remote_content()
exists = File.exists?(@resource[:path])
Updated by AJ Christensen over 4 years ago
Sorry, when the source doesn’t exist? I see the correct error (no valid source found). Am I doing something wrong (from your view?)
root@puppet:/tmp# ls -la /tmp/home/jbq/_svn/conf/apache/sites/
total 8
drwxr-xr-x 2 root root 4096 2008-01-15 22:30 .
drwxr-xr-x 3 root root 4096 2008-01-15 21:56 ..
root@puppet:/tmp# cat test.pp
file { "/tmp/etc/apache2/sites-available/dev-www":
ensure => present,
mode => 640,
owner => root,
group => root,
source => '/tmp/home/jbq/_svn/conf/apache/sites/dev-www'
}
root@puppet:/tmp# ls -la /tmp/home/jbq/_svn/conf/apache/sites/
total 8
drwxr-xr-x 2 root root 4096 2008-01-15 22:30 .
drwxr-xr-x 3 root root 4096 2008-01-15 21:56 ..
root@puppet:/tmp# puppet --verbose --debug test.pp
info: Loading fact interfaces
info: Loading fact netmask
info: Loading fact acpi_available
info: mount[localhost]: Mounted /
info: mount[modules]: Mounted
info: mount[plugins]: Mounted
debug: Creating default schedules
debug: Finishing transaction -608226608 with 0 changes
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/checksum: Initializing checksum hash
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077
debug: mount[localhost]: File source tmp/home/jbq/_svn/conf/apache/sites/dev-www does not exist
info: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/source: No specified sources exist
debug: Finishing transaction -609557668 with 0 changes
Updated by James Turnbull over 4 years ago
Also —trace is not undocumented – please see http://reductivelabs.com/trac/puppet/wiki/ConfigurationReference.
Updated by Jean-Baptiste Quenot over 4 years ago
Replying to [comment:5 jamtur01]:
Also —trace is not undocumented – please see http://reductivelabs.com/trac/puppet/wiki/ConfigurationReference.
Thanks for pointing to the wiki. I meant —trace is not mentioned in the output of
puppetd —help.
Updated by Jean-Baptiste Quenot over 4 years ago
Replying to [comment:4 Fujin]:
Sorry, when the source doesn’t exist? I see the correct error (no valid source found). Am I doing something wrong (from your view?)
Yes I mean when the source does not exist.
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/checksum: Initializing checksum hash
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077
debug: mount[localhost]: File source tmp/home/jbq/_svn/conf/apache/sites/dev-www does not exist
info: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/source: No specified sources exist
debug: Finishing transaction -609557668 with 0 changes
I don’t have those messages in my log. Where does this
mount[localhost]come from?
Updated by AJ Christensen over 4 years ago
Replying to [comment:7 jbq]:
Replying to [comment:4 Fujin]:
Sorry, when the source doesn’t exist? I see the correct error (no valid source found). Am I doing something wrong (from your view?)
Yes I mean when the source does not exist.
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/checksum: Initializing checksum hash debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077 debug: mount[localhost]: File source tmp/home/jbq/_svn/conf/apache/sites/dev-www does not exist info: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/source: No specified sources exist debug: Finishing transaction -609557668 with 0 changesI don’t have those messages in my log. Where does this
mount[localhost]come from?
I believe
mount[localhost]is generated when using ‘puppet’ standalone, which I did.
/tmp/test.pp:
file { "/tmp/etc/apache2/sites-available/dev-www":
ensure => present,
mode => 640,
owner => root,
group => root,
source => '/tmp/home/jbq/_svn/conf/apache/sites/dev-www'
}
output:
info: Loading fact interfaces
info: Loading fact netmask
info: Loading fact acpi_available
info: mount[localhost]: Mounted /
info: mount[modules]: Mounted
info: mount[plugins]: Mounted
debug: Creating default schedules
debug: Finishing transaction -608226608 with 0 changes
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/checksum: Initializing checksum hash
debug: //Filecommit:/tmp/etc/apache2/sites-available/dev-www: Creating checksum {md5}bf3ec5e96cc0166b11352d6b64aca077
debug: mount[localhost]: File source tmp/home/jbq/_svn/conf/apache/sites/dev-www does not exist
info: //Filecommit:/tmp/etc/apache2/sites-available/dev-www/source: No specified sources exist
debug: Finishing transaction -609557668 with 0 changes
Updated by Jean-Baptiste Quenot over 4 years ago
I believe the error only occurs when using the client-server mode with puppetd. At least this is my setup.
Updated by AJ Christensen over 4 years ago
I see. My apologies. I’ve tested in client<>server mode, and am able to replicate your issue.
node puppet {
include puppetmaster
include monitoring
include apache2::no_default_site
include git::web
git::web::export {
puppet:
description => "Puppet repository";
asterisk:
description => "Asterisk configuration repository";
}
file { "/tmp/etc/apache2/sites-available/dev-www":
ensure => present,
mode => 640,
owner => root,
group => root,
source => '/tmp/home/jbq/_svn/conf/apache/sites/dev-www'
}
}
root@puppet:/etc/puppet/manifests# runpuppet running puppet, standby. info: Loading fact netmask info: Loading fact acpi_available info: Loading fact interfaces info: Retrieving plugins notice: Ignoring cache info: /Exec[/bin/true # require_lsbdistcodename]: Adding aliases "require_lsbdistcodename" info: /Exec[/bin/true # assert_lsbdistcodename]: Adding aliases "assert_lsbdistcodename" info: /Exec[/usr/bin/apt-get update]: Adding aliases "aptgetupdate" info: /Host[puppet]: Adding aliases "puppet.maxnet.net.nz" info: /Exec[/usr/sbin/a2ensite gitweb]: Adding aliases "a2site-gitweb" info: mount[localhost]: Mounted / info: mount[modules]: Mounted info: mount[plugins]: Mounted info: /Exec[/usr/sbin/a2ensite munin-stats]: Adding aliases "a2site-munin-stats" info: Caching catalog at /var/lib/puppet/state/localconfig.yaml notice: Starting catalog run notice: //Node[puppet]/Git::Web::Export[asterisk]/Exec[/usr/bin/git-update-server-info #/srv/git/asterisk/.git]/returns: executed successfully notice: //Node[puppet]/Git::Web::Export[puppet]/Exec[/usr/bin/git-update-server-info #/srv/git/puppet/.git]/returns: executed successfully info: Loading fact netmask info: Loading fact acpi_available info: Loading fact interfaces err: //Node[puppet]/Filecommit:/tmp/etc/apache2/sites-available/dev-www/ensure: change from absent to present failed: Could not set present on ensure: undefined method @[]' for nil:NilClass at /etc/puppet/manifests/site.pp:37
Cool – could you please attach a unified diff .patch to the ticket (instead of in plaintext in a comment).
Thanks :)
Updated by James Turnbull over 4 years ago
Luke – if you’re happy with the patch – I think it works – then I am happy to commit it.
Updated by Luke Kanies over 4 years ago
- Status changed from 1 to Closed
- 7 set to fixed
This patch doesn’t really supply the correct behaviour, because it should catch the problem in the insync? method, like we try to do normally.
It turns out the the cause for this problem is actually the ‘ensure => present’, because ‘ensure’ doesn’t catch the lack of any existing sources.
Fixed in [2cbab2c]. This is hackish, too, but at least it provides consistent behaviour.
I also upgraded the ‘info’ to ‘warning’.