Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: When adding many host entries, some fail with "Permission denied" errors #9528

Open
dhs-rec opened this issue Nov 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dhs-rec
Copy link

dhs-rec commented Nov 28, 2024

Describe the Bug

When adding many host entries on Windows, using host resources, some sometimes fail with

Puppet::Util::FileType::FileTypeFlat could not write C:/Windows/System32/drivers/etc/hosts: Permission denied @ rb_sysopen - C:/Windows/System32/drivers/etc/hosts

while the other ones are added just fine.

Expected Behavior

All host entries should be added w/o error

Steps to Reproduce

Use the following class to add many host entries to a new Windows node (possibly in a setup with at least 20-30 other nodes):

class hosts {
  # Let each host create a host entry as exported resource
  $nic = $facts['networking']['primary']
  $ip = $facts['networking']['interfaces'][$nic]['ip']

  @@host { $facts['networking']['fqdn']:
    comment      => 'Host entry generated by Puppet',
    host_aliases => [$facts['networking']['hostname']],
    ip           => $ip,
    tag          => ['HOST_RECORD'],
  }

  # Collect all exported host records and add them to (C:/Windows/System32/drivers)/etc/hosts
  Host <<| tag == 'HOST_RECORD' |>> { ensure => present }
}

Environment

  • Version: 7
  • Platform: Windows Server 20xx

Additional Context

Could work around/fix the problem with the following patch:

*** /usr/lib/ruby/vendor_ruby/puppet/util/filetype.rb   2023-02-07 22:38:26.000000000 +0100
--- Windows/filetype.rb 2024-11-28 10:46:10.605288810 +0100
***************
*** 127,132 ****
--- 127,133 ----
        File.chmod(@default_mode, tf.path) if @default_mode
        FileUtils.cp(tf.path, @path)
        tf.close
+       sleep(0.1) if Facter.value(:kernel) == 'windows'
        # If SELinux is present, we need to ensure the file has its expected context
        set_selinux_default_context(@path)
      end
@dhs-rec dhs-rec added the bug Something isn't working label Nov 28, 2024
@dhs-rec
Copy link
Author

dhs-rec commented Nov 28, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant