puppet-network
puppet-network copied to clipboard
Double initialisation of "interfaces" provider causes exception (aka can't purge unmanaged config)
Due to some autoloading behaviour when using resources{'network_config': purge => true}
or crayfishx/purge
2 instances of the provider get created.
This creates a problem because FileMapper
calls parse_file('/etc/network/interfaces')
twice, resulting in it detecting duplicate interfaces since the parse state gets kept globally between runs in the Instance
class.
Affected Puppet, Ruby, OS and module versions/distributions
- Puppet: 6.6.0
- Distribution: debian (stretch)
- Module version: master (as of writing)
How to reproduce (e.g Puppet code you use)
resources { 'network_config':
purge => true,
}
What are you seeing
Error: Could not prefetch network_config provider 'interfaces': Malformed debian interfaces file; cannot instantiate network_config resources
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:39:in `raise_malformed'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:181:in `block (2 levels) in parse_file'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:174:in `match'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:174:in `block in parse_file'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:130:in `each'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:130:in `parse_file'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:172:in `block in load_all_providers_from_disk'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:166:in `each_pair'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:166:in `load_all_providers_from_disk'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:102:in `instances'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:192:in `prefetch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:364:in `prefetch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:256:in `prefetch_if_necessary'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:111:in `block in evaluate'
What behaviour did you expect instead
No exceptions and removal of unmanaged config
Possible fixes:
- hard way: keep track of which files we have already parsed and just refuse to parse the same file twice
- easy way: call
Instance.reset!
at the beginning ofself.parse_file
since we only ever parse one file. - the brute-force way: remove the duplicity check. (not really an option though)
Which one would you like me to take a look at for a PR?
Related issues:
This is likely to be the root issue behind stuff like #60 and #44
also
Network_config {
ensure => purged
}
as sugested in #78 does not work for this and even if it did it still wouldn't fix the crayfishx/purge
usecase.